集成google plus时会发生内部错误

时间:2013-09-03 10:55:32

标签: android google-plus

我正在开发一个Google+集成应用程序。我参考了Google+官方教程。我的问题是,当我按下登录按钮时,它显示一个Toast消息错误“内部错误发生”。我不知道为什么会出现这种错误,我看到以下链接但没有得到任何输出....

First Link

Second Link

Third Link

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.Toast;
import com.example.bluetoothsocialsharing.R;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
import com.google.android.gms.plus.PlusClient;
public class GooglePlusActivity extends Activity implements ConnectionCallbacks, OnConnectionFailedListener
{

    //static final String[] SCOPES = new String[] { Scopes.PLUS_PROFILE };

    @Override
    protected void onStop() {
        super.onStop();
        mPlusClient.disconnect();
    }
    /*@Override
    protected void onDestroy() {
        super.onDestroy();
        mPlusClient.disconnect();
    }*/
    @Override
    protected void onStart() {
        super.onStart();
        mPlusClient.connect();
    }
        private static final String TAG = "ExampleActivity";
        private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
        private ProgressDialog mConnectionProgressDialog;
        private PlusClient mPlusClient;
        private ConnectionResult mConnectionResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_google_plus);
        mPlusClient = new PlusClient.Builder(this, this, this)
        .setVisibleActivities("http://schemas.google.com/AddActivity","http://schemas.google.com/BuyActivity")
        .build();
        //mPlusClient=new PlusClient(this,this,this,SCOPES);
        // Progress bar to be displayed if the connection failure is not resolved.
        mConnectionProgressDialog = new ProgressDialog(this);
        mConnectionProgressDialog.setMessage("Signing in...");
        mConnectionProgressDialog.show();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.google_plus, menu);
        return true;
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        Log.i(TAG,"ConnectionResult:"+result);
      if (mConnectionProgressDialog.isShowing()) {
        // The user clicked the sign-in button already. Start to resolve
        // connection errors. Wait until onConnected() to dismiss the
        // connection dialog.
        if (result.hasResolution()) {
          try {
                Log.i(TAG,"EnterTryBlock");
                   result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
           } catch (SendIntentException e) {
               Log.i(TAG,"EnterCatchBlock");
                   mPlusClient.connect();
           }
        }
      }
      // Save the result and resolve the connection failure upon a user click.
      setmConnectionResult(result);
    }

    @Override
    protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
        if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
            setmConnectionResult(null);
            mPlusClient.connect();
        }
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        String accountName = mPlusClient.getAccountName();
        Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG).show();
    }
    @Override
    public void onDisconnected() {
        Log.d(TAG, "disconnected");
    }

    public ConnectionResult getmConnectionResult() {
        return mConnectionResult;
    }

    public void setmConnectionResult(ConnectionResult mConnectionResult) {
        this.mConnectionResult = mConnectionResult;
    }
}

4 个答案:

答案 0 :(得分:2)

Satheesh,

一旦goto删除该文件.android / debug.keystore重启后你的eclipse。 Window - >上有新密钥Prefernces - > Android - > SHA1指纹密钥你只需复制它并在你的控制台页面添加新项目并粘贴你的新密钥和包名称。尝试工作后......

答案 1 :(得分:1)

我遇到了同样的问题。在指南中它说

mPlusClient = new PlusClient.Builder(this, this, this)
                .setActions("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity")
                .setScopes("PLUS_LOGIN")  // Space separated list of scopes
                .build();

我把它改成了它并且它起作用了

mPlusClient = new PlusClient.Builder(this, this, this)
                .setActions("http://schemas.google.com/AddActivity",
                        "http://schemas.google.com/BuyActivity")
                .build();

如果您使用Eclipse测试应用程序,请确保在Window中使用SHA1指纹 - > Prefernces - > Android - >在您的Google +控制台中构建

答案 2 :(得分:0)

我解决了我的问题。 用密码android重新创建一个sha1键。现在这对我很好。所以问题在于创建sha1密钥。

答案 3 :(得分:0)

这里有一个案例,解决它可以帮助我正常运行我的应用程序

"An internal error occurred" with integration of Google Plus Login

所以,这个答案说你应该填写"同意屏幕"在谷歌开发者控制台的左侧菜单中,你注册你的应用程序。

以下是它的样子:enter image description here