通过 android 和 iPhone 应用程序集成 yahoo、Google 和 openid?

发布于 2024-11-15 12:54:40 字数 203 浏览 1 评论 0原文

我正在为 iPhone 和 Android 设计一个应用程序,其中必须集成 facebook、twitter、yahoo、gmail、openId。我已经集成了 facebook 和 twitter,但是如何集成 yahoo、gmail 和 openId?如何通过应用程序登录这些并获取用户信息?

请告诉我一种实现这一点的方法。任何教程都可能有所帮助。

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愁杀 2024-11-22 12:54:40
    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);

解析响应以获取 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);

解析响应并享受:)

    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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文