0

我尝试在我的 Android 应用程序中使用 google plus api。我遵循示例代码

我成功连接到 google plus,并请求加载人员,但 personBuffer 计数为 0。但我的组中有一些人。

请告诉我任何想法?也许我忘记了任何附加范围?我只添加 Scopes.PLUS_LOGIN。在文档中就足够了。

我的完整授权代码:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mPlusClient = new PlusClient.Builder(this, this, this).setScopes(Scopes.PLUS_LOGIN, Scopes.PLUS_PROFILE)
                .setVisibleActivities("http://schemas.google.com/AddActivity").build();

        // Progress bar to be displayed if the connection failure is not
        // resolved.
        mConnectionProgressDialog = new ProgressDialog(this);
        mConnectionProgressDialog.setMessage("Signing in...");

    }


@Override
    protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
        if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
            mConnectionResult = null;
            mPlusClient.connect();
        }
    }
@Override
    public void onConnected(Bundle connectionHint) {
        String accountName = mPlusClient.getAccountName();
//      mPlusClient.loadPerson(this, "104242357859551899867");
//
        mPlusClient.loadPeople(MainActivity.this, Person.Collection.VISIBLE);

        Toast.makeText(this, accountName + " is connected. try to load persons", Toast.LENGTH_LONG).show();
    }
@Override

public void onPeopleLoaded(ConnectionResult status, PersonBuffer personBuffer, String nextPageToken) {
    Log.i("", "persons loaded result = " + status.toString() + ", personsCount = " + personBuffer.getCount()
            + ", token = " + nextPageToken);
    if (status.isSuccess()) {
        Iterator<Person> itP = personBuffer.iterator();
        while (itP.hasNext()) {
            Person person = itP.next();
            Log.i("", person.getNickname());
        }
    }

}

我完整的logcat:

    06-14 11:38:43.451: D/libEGL(779): loaded /system/lib/egl/libEGL_adreno200.so
06-14 11:38:43.451: D/libEGL(779): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
06-14 11:38:43.451: D/libEGL(779): loaded /system/lib/egl/libGLESv2_adreno200.so
06-14 11:38:43.451: I/Adreno200-EGL(779): <eglInitialize:269>: EGL 1.4 QUALCOMM build: Nondeterministic AU_full_mako_PARTNER-ANDROID/JB-MR1-DEV_CL2961380_release_AU (CL2961380)
06-14 11:38:43.451: I/Adreno200-EGL(779): Build Date: 12/10/12 Mon
06-14 11:38:43.451: I/Adreno200-EGL(779): Local Branch: 
06-14 11:38:43.451: I/Adreno200-EGL(779): Remote Branch: m/partner-android/jb-mr1-dev
06-14 11:38:43.451: I/Adreno200-EGL(779): Local Patches: NONE
06-14 11:38:43.451: I/Adreno200-EGL(779): Reconstruct Branch: NOTHING
06-14 11:38:43.491: D/OpenGLRenderer(779): Enabling debug mode 0
06-14 11:38:44.993: I/(779): persons loaded result = ConnectionResult{statusCode=SUCCESS, resolution=null}, personsCount = 0, token = null
06-14 11:38:45.013: D/dalvikvm(779): GC_CONCURRENT freed 165K, 3% free 8898K/9092K, paused 2ms+3ms, total 27ms
4

1 回答 1

0

解决方法是像这样初始化 PlusClient:

mPlusClient = new PlusClient.Builder(this, this, this).build();

上面的代码工作正常。

于 2013-06-17T13:30:04.660 回答