2016-08-03 9 views
6

Plus.APIGoogle Play Services 9.4で非推奨になりました。Androidアプリで認証されたユーザーのためにGoogle Plusサークルを取得する正しい方法は何ですか?推奨されていませんPlus.PeopleApi.load

今、私たちは推奨しているロードの方法に加えて、ユーザーPlus.PeopleApi.load

新しいドキュメントは言う:

あなたのアプリは、ソーシャル情報や、より広範なプロファイルデータ、 チェックアウトAndroidの連絡先プロバイダまたはクロスを必要とする場合 - プラットフォームの人々 API。

だから私はAndroidの連絡先(私はランタイム権限をカーソルとの接触をフィルタリングしても管理する必要があるため)ハード選択肢であるように思わプロバイダに行く必要があります。

いずれかの簡単な代替方法以前の使用されなくなった方法ただGのサークルの一覧を取得するには?

+0

あなたは、私が上記の質問で述べたように、今ではコンタクトAPI *または*プロバイダ –

+0

を推薦だ、プラスのAPIを使用していたが、私はこれらのソリューションが存在することを知っています。しかし、彼らは前にあったものの難しい選択肢です。 私は、カーソルの使用と実行時パーミッションの管理が、単純な方法の代わりであるとは思わない。 –

+0

カーソルはプロバイダ専用です(はい)? [連絡先API](https://developers.google。 –

答えて

4

Google+の人々APIは、最終的には詳細については非推奨ノート下記参照、2017年Q1に完全に廃止されます:

アンドロイド発表: https://developers.google.com/+/mobile/android/api-deprecation

RESTエンドポイントの発表: https://developers.google.com/+/web/people/#retrieve-a-collection-of-people

だから、代替案を検討すべきですplus.loginスコープを持つ新しいユーザーにはデータが提供されませんので、G + Circleの友人に基づく新しい機能を提案して作成しないでください。

実行時アクセス権を要求したくない場合でも、ログインしたユーザーの連絡先をPeople REST APIから得ることができます(これはG + People APIとは異なるものです)。また、サインインAPIによって既に提供されているfirst/last/display name、email、profile picture url以外のログインユーザーのプロファイル情報が必要な場合は、同じ新しい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' 

次に、サインインコードを書き込みます。

次に、新しい人物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(); 
     ... 
    } 
} 
+0

を使用するように依頼していますが、「googleSignInAccount」はどこから取得しますか? –

+1

GoogleSignInApiを使用してgetSignInIntent(mGoogleApiClient)を呼び出し、インテントを起動します。 onActivityResultで、GoogleSignInAccountを取得することができます。詳細については、このドキュメントを参照してください:https://developers.google.com/identity/sign-in/android/sign-in –

+0

ありがとうイザベラ、この人のAPI [問題](http://stackoverflow.com/questions/40278457/android-google-people-api-error-tokenresponseexception-missing-parameter-code)も同様ですか?どうもありがとう ! –

関連する問題