1

我正在使用 Google 登录来获取基本的用户个人资料数据,但我需要从 Google Plus 获取用户的封面照片。我知道 Google Plus 已被弃用,因此我阅读了有关 Google People Api 的信息。问题是,当我尝试实现此处公开的示例时,由于包不存在,以下代码行无法解析,

People peopleService = new People.Builder(httpTransport, jsonFactory, credential)
    .build();

文档的示例使用

import com.google.api.services.people.People;

但如果我尝试导入该包,它不存在。我只能导入

com.google.api.services.people.v1.PeopleService.People

并且使用该包, Builder 方法不存在。

这是我的 Gradle 文件,

compile 'com.google.android.gms:play-services-auth:10.2.1'
compile 'com.google.android.gms:play-services-plus:10.2.1'
compile 'com.google.apis:google-api-services-people:v1-rev91-1.21.0'
compile 'com.google.http-client:google-http-client-android:1.17.0-rc' exclude module: 'httpclient'
compile 'com.google.api-client:google-api-client-android:1.17.0-rc' exclude module: 'httpclient'
compile 'com.google.api-client:google-api-client-gson:1.17.0-rc' exclude module: 'httpclient'
compile 'com.google.api-client:google-api-client:1.21.0'

在这里,我向您展示了我如何尝试实现 Google People Api,

public static People setUp(Context context, String serverAuthCode) throws IOException {
    HttpTransport httpTransport = new NetHttpTransport();
    JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();

    // Redirect URL for web based applications.
    // Can be empty too.
    String redirectUrl = "urn:ietf:wg:oauth:2.0:oob";

    // STEP 1
    GoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(
            httpTransport,
            jsonFactory,
            context.getString(R.string.default_web_client_id),
            context.getString(R.string.default_web_client_id),
            serverAuthCode,
            redirectUrl).execute();

    // STEP 2
    GoogleCredential credential = new GoogleCredential.Builder()
            .setClientSecrets(context.getString(R.string.default_web_client_id), context.getString(R.string.default_web_client_id))
            .setTransport(httpTransport)
            .setJsonFactory(jsonFactory)
            .build();

    credential.setFromTokenResponse(tokenResponse);

    // STEP 3
    return new com.google.api.services.people.v1.PeopleService.People.Builder(httpTransport, jsonFactory, credential)
            .setApplicationName("")
            .build();
}
4

1 回答 1

0

看起来示例是错误的,您需要使用PeopleService.Builder

于 2017-06-21T18:28:09.917 回答