Integrate yahoo, Google and openid through android and iPhone application?

若如初见. 提交于 2019-12-21 02:56:09

问题


I am designing an app for iPhone and android in which I have to integrate facebook, twitter, yahoo, gmail, openId. I had integrated facebook and twitter, but how to go for yahoo, gmail and openId? How to login these through app and get the user information?

Please do show me a way to implement this. Any tutorial may help.

Thanks.


回答1:


To integrate gmail may this url's help you
Google's documentation
Introduction about integrating gmail with iphone
Examples to integrate with iphone
Api's for integrating blogger,google analytics etc
For yahoo you can use this




回答2:


    String YAHOO_RESOURCE_URL = "http://social.yahooapis.com/v1/me/guid/profile?fomat=xml";
    String CALLBACK_URL = "oauth://testApp";
    String YAHOO_REQUEST_TOKEN_URL = "https://api.login.yahoo.com/oauth/v2/get_request_token";
    String YAHOO_ACCESS_TOKEN_URL = "https://api.login.yahoo.com/oauth/v2/get_token";
    String YAHOO_AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth";

    // Oauth consumer and provider.
    CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(Constants.YAHOO_CONSUMER_KEY, Constants.YAHOO_CONSUMER_SERECT_KEY);
    OAuthProvider provider = new CommonsHttpOAuthProvider(YAHOO_REQUEST_TOKEN_URL , YAHOO_ACCESS_TOKEN_URL, YAHOO_AUTHORIZE_URL);
    provider.setOAuth10a(true);

    // First retrive request token.
    String authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
    String yahooToken = consumer.getToken();
    String yahooTokenSecret = consumer.getTokenSecret();

    Open the authUrl in android web browser, this will launch login page, then after login will ask for permissions, accepting the permissions will return in your app using callback url.

    Now,
    In onResume

    Uri uri = this.getIntent().getData();
    if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {

    String oauthToken = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_TOKEN);
    String oauthVerifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);

    consumer = new CommonsHttpOAuthConsumer(Constants.YAHOO_CONSUMER_KEY, Constants.YAHOO_CONSUMER_SERECT_KEY);
    consumer.setTokenWithSecret(yahooToken, yahooTokenSecret);

    provider = new CommonsHttpOAuthProvider(YAHOO_REQUEST_TOKEN_URL, YAHOO_ACCESS_TOKEN_URL, YAHOO_AUTHORIZE_URL);
    provider.setOAuth10a(true);

    // Now retrive access token
    provider.retrieveAccessToken(consumer, oauthVerifier);
    String token = consumer.getToken();
    String tokenSecret = consumer.getTokenSecret();
    consumer.setTokenWithSecret(token, tokenSecret);

    //  Get the GUID from this.
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet request = new HttpGet("http://social.yahooapis.com/v1/me/guid?format=json");
    consumer.sign(request);
    HttpResponse response = httpClient.execute(request);

Parse the response to get GUID.

    // Now use the GUID to get profile info.
    DefaultHttpClient httpClient = new DefaultHttpClient();
    String strUrl = "http://social.yahooapis.com/v1/user/"+ strGUID +"/profile?format=json";
    HttpGet request = new HttpGet(strUrl);
    consumer.sign(request);
    HttpResponse response = httpClient.execute(request);

Parse the response and njoy :)



来源:https://stackoverflow.com/questions/6346409/integrate-yahoo-google-and-openid-through-android-and-iphone-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!