Google+에서 사람들 API는 결국 완전히 자세한 내용은 중단 노트 아래 참조 2017 년 Q1을 더 이상 사용되지 않습니다 plus.login 범위가 인 신규 사용자에게는 데이터를 사용할 수 없으므로 G + Circle 친구들을 기반으로 새로운 기능을 제안하고 빌드하지 마십시오.
런타임 권한을 요청하지 않으려는 경우에도 로그인 한 사용자의 연락처를 People REST API (여전히 G + People API와 다른 점을 유의하십시오)에서받을 수 있습니다. 또한 첫 번째/마지막/표시 이름, 이메일 및 프로필 사진 URL (로그인 API에서 이미 제공됨) 이외의 로그인 한 사용자의 프로필 정보가 필요한 경우 동일한 새 People API도 사용해야합니다.
안드로이드에
, 당신이 연락처 데이터를 필요로 할 때
(당신이 자신의 연락처를 요구하는 이유를 사용자에게 설명하는 맥락에서
을, 정보. 프런트 도어 로그인 활동에서 선행 접촉 범위를 요청하지 마십시오)
// Add dependencies (SDKs will be downloaded from mavenCentral)
compile 'com.google.api-client:google-api-client:1.22.0'
compile 'com.google.api-client:google-api-client-android:1.22.0'
compile 'com.google.apis:google-api-services-people:v1-rev4-1.22.0'
그런 다음 로그인 코드를 작성하십시오.
// Make sure your GoogleSignInOptions request email & contacts scopes as shown below
GoogleSignInOptions gso =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestScopes(new Scope(PeopleScopes.CONTACTS_READONLY)))
.build();
// Follow official doc to sign-in.
// https://developers.google.com/identity/sign-in/android/sign-in
그러면 새로운 사람 API를 사용하여 연락처 목록을 검색 할 수 있습니다.
/** Global instance of the HTTP transport. */
private static HttpTransport HTTP_TRANSPORT = AndroidHttp.newCompatibleTransport();
/** Global instance of the JSON factory. */
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
// On worker thread
GoogleAccountCredential credential =
GoogleAccountCredential.usingOAuth2(MainActivity.this, PeopleScopes.CONTACTS_READONLY);
credential.setSelectedAccount(
new Account(googleSignInAccount.getEmail(), "com.google"));
People service = new People.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME /* whatever you like */)
.build();
ListConnectionsResponse response = service.people().connections()
.list("people/me")
// request 20 contacts
.setPageSize(20)
.execute();
List<Person> connections = response.getConnections();
if (connections != null && connections.size() > 0) {
for (Person person : connections) {
List<Name> names = person.getNames();
if (names != null && names.size() > 0) {
Log.i(TAG, "Name: " + person.getNames().get(0).getDisplayName());
} else {
Log.i(TAG, "No names available for connection.");
}
List<Gender> genders = person.getGenders();
String ageRange = person.getAgeRange();
List<Birthday> birthdays = person.getBirthdays();
...
}
}
당신은 내가 위의 질문에 말했듯이 지금은 연락처 API의 * 또는 * 공급자 –
을 추천하는 것, 플러스의 API를 사용하고, 나는 이러한 솔루션이 존재한다는 것을 알고있다. 그러나 그들은 전에 있었던 것의 너무 어려운 대안이다. 커서를 사용하고 런타임 권한을 관리하는 것이 간단한 방법의 대안이라고 생각하지 않습니다. –
커서는 제공자 전용입니다. 그렇습니까? [주소록 API] (https://developers.google.com/google-apps/contacts/v3 /) –