我使用Google登录来获取基本用户的个人资料数据,但我需要从Google Plus获取用户的封面照片。我知道Google Plus已被弃用,所以我读到了Google People Api。问题是,当我尝试实现公开的here示例时,由于包不存在,无法解析以下代码行,
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();
}