Google+的Andr​​oid版签到"发生与QUOT内部错误; [英] Android Google+ Signin "An internal error has occurred"

查看:310
本文介绍了Google+的Andr​​oid版签到"发生与QUOT内部错误;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个应用程序,允许用户通过Facebook或Google+登录。我做了什么是写为登录一个接口,以使任何一个都可以使用。 Facebook登录拼凑自己的文档小时后去就好了。 Google+的,另一方面有我百思不得其解,也许我刚刚被它太长时间盯着。我一般都可以找到SO决议,以我的问题,但它一直在寻找答案的日子。

I'm writing an app that allows users to login via Facebook or Google+. What I've done is write an interface for the login, so that either one can be used. Facebook login went just fine after hours of piecing together their documentation. Google+ on the other hand has me baffled, or maybe I've just been staring at it too long. I can generally find resolutions to my problems on SO, but it's been over a day of searching for an answer.

我实现了开始使用Google+平台一行一行。我跑我的应用程序和我说要我批准我的应用程序来访问我的Google+帐户的页面。我点击批准和我的应用程序崩溃。 :捂脸:我没在控制台添加了Google+ API。我已经使用谷歌地图,所以只好跳过这部分。

I implemented the Getting Started with Google+ Platform line by line. I ran my application and I got the page that asked me to approve my app to access my Google+ account. I click Approve and my app crashes. :facepalm: I didn't add the Google+ API in console. I was already using Google Maps, so I had skipped that part.

现在会发生什么?我有导致敬酒说:发生内部错误的连接尝试的无限循环。我不再显示Google+批准屏幕。我试着从<一以下解决方案href=\"http://stackoverflow.com/questions/15762904/an-internal-error-occurred-with-integration-of-google-plus-login\">SO 15762904 :

Now what happens? I have an infinite loop of connection attempts resulting in Toasts saying "An internal error has occurred". I no longer get a Google+ approval screen. I've tried the following solutions from SO 15762904:


  • 生成一个新的控制台密钥(即使谷歌地图是工作的罚款)

  • 填充了我的同意画面与电子邮件和产品名称

  • 答案很多涉及从去$ P $删除.setScopes()pcated PlusClient API,在这里并不适用

  • 双重检查,在开发者控制台SHA指纹是用于生成API密钥相同

  • 在设备上已注销的Google+

下面是主要的活动code。 mSession 是我使用的登录会话变量。我没有按键的设置,现在,我一般去功能GUI之前。

Here is the main activity code. mSession is the variable I use for logins sessions. I don't have buttons setup right now, I generally go for functionality before GUI.

private Login mSession;

/**************************************************************************
 * Activity life cycle methods
 **************************************************************************/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Populate the main content
    if (savedInstanceState == null) {
        mSession = new GooglePlusLogin(this);
        mSession.openSession();
    }
}

@Override
protected void onStart() {
    super.onStart();

    // Call login session onStart() method
    mSession.onStart();
}

@Override
protected void onStop() {
    super.onStop();

    // Call login session onStop() method
    mSession.onStop();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    mSession.onActivityResult(requestCode, resultCode, data);

}

下面是实现登录界面中的GoogleLogin类。

Here is the GoogleLogin class that implements the login interface.

public class GooglePlusLogin implements Login, ConnectionCallbacks, OnConnectionFailedListener{

private boolean mIntentInProgress;
private Activity mActivity;
private Context mContext;
private GoogleApiClient mGoogleApiClient;
private String mSessionToken;

public GooglePlusLogin(Activity activity) {
    mGoogleApiClient = null;
    mSessionToken = null;
    mIntentInProgress = false;
    mContext = activity.getApplicationContext();
    mActivity = activity;
}

@Override
public boolean openSession() {
    boolean ret = false;

    Log.d(Helper.TAG, "openSession()");
    try {
        if(null != mContext) {
            Log.d(Helper.TAG, "null != mContext");

            mGoogleApiClient = 
                    new GoogleApiClient.Builder(mContext)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(Plus.API)
                    .addScope(Plus.SCOPE_PLUS_LOGIN)
                    .build();

            Log.d(Helper.TAG, "mPlusClient = " + mGoogleApiClient);

            ret = true;
        }
        else {
            throw new LoginException("GooglePlusLogin context NULL");
        }
    }
    catch(LoginException e) {
        Log.d(Helper.TAG, "" + e.toString());
    }

    Log.d(Helper.TAG, "Returning " + ret);

    return ret;
}

@Override
public void onActivityResult(int reqCode, int respCode, Intent intent) {
    Log.d(Helper.TAG, "onActivityResult()");

    if(Helper.GOOGLE_SIGN_IN == reqCode) {
        mIntentInProgress = false;

        if(!mGoogleApiClient.isConnected()) {
            Log.d(Helper.TAG, "Not connected to Google Services, try again");
            mGoogleApiClient.connect();
        }
        else {
            Log.d(Helper.TAG, "Already connected to Google Services");
        }
    }
}

@Override
public void onStart() {
    Log.d(Helper.TAG, "onStart()");

    mGoogleApiClient.connect();
}

@Override
public void onStop() {
    Log.d(Helper.TAG, "onStop()");
    if(mGoogleApiClient.isConnected()) {
        mGoogleApiClient.disconnect();
    }
}

/*************************************************************************
 * Google+ Interface callbacks for GoogleApiClient
 *************************************************************************/
@Override
public void onConnectionFailed(ConnectionResult result) {
    Log.d(Helper.TAG, "onConnectionFailed()");

    if(!mIntentInProgress && result.hasResolution()) {
        try {
            Log.d(Helper.TAG, "Try a Resolution");

            mIntentInProgress = true;

            //mActivity.startIntentSenderForResult(
            //      result.getResolution().getIntentSender(), 
            //      Helper.GOOGLE_SIGN_IN, 
            //      null, 
            //      0, 
            //      0, 
            //      0, 
            //      null
            //      );

            result.startResolutionForResult(mActivity, Helper.GOOGLE_SIGN_IN);
        }
        catch(SendIntentException e) {
            // Intent got canceled during processing, lets try and connect
            // again.
            Log.d(Helper.TAG, "Connect again");

            mIntentInProgress = false;
            mGoogleApiClient.connect();
        }
    }
    else {
        // Something terrible has happened with our connection to 
        // GooglePlay Services
    }
}

@Override
public void onConnected(Bundle connHint) {
    // Do my stuff, but I never get to this point
}

@Override
public void onConnectionSuspended(int arg0) {
    Log.d(Helper.TAG, "onConnectionSuspended()");
    // The connection was suspended... lets try again
    mGoogleApiClient.reconnect();
}

下面是我的Andr​​oidManifest.xml中的相关部分。

Here are the pertinent sections of my AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"
    />    

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    >

    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/app_id_facebook"
        />
    <meta-data 
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"
        />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/app_id_google"
        />

下面是logcat的输出:

Here's the logcat output:

07-04 11:08:25.354: D/  App(15944): openSession()
07-04 11:08:25.354: D/  App(15944): null != mContext
07-04 11:08:25.364: D/  App(15944): mPlusClient = com.google.android.gms.common.api.b@42238088
07-04 11:08:25.364: D/  App(15944): Returning true
07-04 11:08:25.364: D/  App(15944):  Main AuthToken: null
07-04 11:08:25.364: D/  App(15944): onStart()
07-04 11:08:25.615: D/  App(15944): onConnectionFailed()
07-04 11:08:25.615: D/  App(15944): Try a Resolution
07-04 11:08:27.106: D/  App(15944): onActivityResult()
07-04 11:08:27.106: D/  App(15944): Not connected to Google Services, try again
07-04 11:08:27.176: D/  App(15944): onConnectionFailed()
07-04 11:08:27.176: D/  App(15944): Try a Resolution
07-04 11:08:28.538: D/  App(15944): onActivityResult()
07-04 11:08:28.538: D/  App(15944): Not connected to Google Services, try again
07-04 11:08:28.668: D/  App(15944): onConnectionFailed()
07-04 11:08:28.668: D/  App(15944): Try a Resolution
07-04 11:08:29.248: D/  App(15944): onActivityResult()
07-04 11:08:29.248: D/  App(15944): Not connected to Google Services, try again
07-04 11:08:29.479: D/  App(15944): onConnectionFailed()
07-04 11:08:29.479: D/  App(15944): Try a Resolution
07-04 11:08:30.970: D/  App(15944): onStop()

我希望这是一些简单的我只是俯瞰。该入门指南似乎有它的一些过时的信息:

I hope this is something simple that I'm just overlooking. The Get Started guide seemed to have some outdated information in it:


  • mGoogleApiClient.addScope(Plus.API,NULL)崩溃我的应用程序

  • result.getSenderIntent()不存在,你可以看到两种方式我试图创建活动。

大部分AP preciation的人谁可以提供帮助。

Much appreciation to anyone who can help.

推荐答案

我有同样的问题,并通过这样解决。

I have the same issue and resolve by doing this.

在谷歌网页API控制台。

On page Google api console.


  1. 创建一个客户端ID

  2. 应用程序类型要安装的应用程序。

  3. 选择Android的(如果是Android)和把你的SHA1和包名。

现在的重要组成部分。

点击同意画面下方左侧潘内尔菜单上的API上
 和填写的信息

Click on consent screen below to the apis on left pannel menu and fill the information

您有done.Now运行应用程序。

You have done.Now run the application.

感谢

这篇关于Google+的Andr​​oid版签到&QUOT;发生与QUOT内部错误;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆