谷歌加上在android中使用社交认证库的集成

时间:2013-11-29 14:35:14

标签: android authentication google-plus social

我已经使用社交认证成功整合了facebook,twitter 但是我在整合google plus integration时遇到了问题。我可以登录但无法共享任何内容。

错误: - org.brickred.socialauth.exception.SocialAuthException:java.io.FileNotFoundException:https://accounts.google.com/o/oauth2/token

如果有人有意,请回复。

提前致谢....

我使用以下代码: -

验证: -

SocialAuthAdapter googlePlusAdapter;

    try
            {
                            googlePlusAdapter = new SocialAuthAdapter(new ResponseListener());
                            googlePlusAdapter.addCallBack(Provider.GOOGLEPLUS, "http://localhost");
                            googlePlusAdapter.authorize(this,org.brickred.socialauth.android.SocialAuthAdapter.Provider.GOOGLEPLUS);
            } catch (Exception e) {

                            Toast.makeText(getApplicationContext(),"Exception " + e.toString(), 1).show();
           }

分享: -

        try{

             String msg="post from my app"; 

        googlePlusAdapter.updateStatus(msg, new SocialAuthListener<Integer>() {

            @Override
            public void onExecute(String arg0, Integer t) {
                // TODO Auto-generated method stub
                Integer status = t;
                if (status.intValue() == 200 || status.intValue() == 201 ||status.intValue() == 204)
                {    Toast.makeText(getApplicationContext(), "Message posted",Toast.LENGTH_LONG).show();
                     googlePlusAdapter.signOut(Provider.GOOGLEPLUS.toString()); 
                }
                else
                Toast.makeText(getApplicationContext(), "Message not posted",Toast.LENGTH_LONG).show();
            }

            @Override
            public void onError(SocialAuthError error) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "Message not posted!! Try again",Toast.LENGTH_LONG).show();
            }
        }, true);

        finish();
        }
        catch(Exception e)
        {

        }

1 个答案:

答案 0 :(得分:1)

问题是您已为Android应用程序创建了客户端ID。 您必须为Web应用程序创建客户端ID,然后在该选项中您必须为redirect_uri提供帮助。

步骤:

  1. 转到https://cloud.google.com/console/project
  2. 选择您的项目
  3. 选择API&amp; auth,然后是凭据
  4. 按Crate新客户ID
  5. 创建Web应用程序类型。
  6. 放置一个可以响应YOUR_URL / oauth2callback
  7. 的有效uri

    所以在你的代码中:

    googlePlusAdapter.addCallBack(Provider.GOOGLEPLUS, "http://localhost");
    

    你必须这样写:

    googlePlusAdapter.addCallBack(Provider.GOOGLEPLUS, same_uri_you_put_in_redirect_uri);
    

    这是因为socialauth通过http进行身份验证。