0

アプリケーションにGoogle+ログインを追加しました。アカ​​ウント名を取得したら、次の方法で基本的なユーザープロファイル情報を取得します。

URL url = new URL("https://www.googleapis.com/oauth2/v1/userinfo");
//get Access Token with Scopes.PLUS_PROFILE
String sAccessToken = GoogleAuthUtil.getToken(mActivity.this,
                        mPlusClient.getAccountName() + "",
                        "oauth2:" + Scopes.PLUS_PROFILE
                        + " https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email");
                        urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Authorization", "Bearer "
        + sAccessToken);
BufferedReader r = new BufferedReader(new InputStreamReader(
        urlConnection.getInputStream(), "UTF-8"));
StringBuilder total = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
    total.append(line);
}
line = total.toString();

それは通常私にこれらの詳細を与えます:

"id" "email" "give_name" "family_name" "name" "link" "verified_email" "gender" "locale" "picture"

しかし、テスト中に、とを使用して新しいGoogleアカウントを作成しましfirstNameLastName。そして、それは私のGoogle+アカウントに表示されます。

しかし、このアカウント名でユーザー情報の同じAPIを呼び出すと、次のようになります。

{"id": "xxxxxxxxxxxxxxxxxxxxxx"、 "email": "xxxxxx@gmail.com"、 "verified_email":true、 "locale": "en"}

名前とは何の関係もありません。

そのような場合の回避策はありますか?

ありがとうございました

4

2 に答える 2

1

Google+ログインの場合、少し違う方法でログインする必要はありません。userinfoエンドポイントにアクセスするのではなく、Google +プロファイルエンドポイントにアクセスします:https ://developers.google.com/+/api/latest/people/get 。Androidの場合、これはGoogle PlayサービスのPlusClientでヘルパーメソッドを呼び出すのと同じくらい簡単です。mPlusClient.loadPerson(this、 "me");

ユーザーIDとして「me」を使用すると、表示名を含む、現在サインインしているユーザーのプロファイルが返されます。

使用しているスコープは機能しますが、userinfo.profileは必要ありません。また、PLUS_PROFILEをPLUS_LOGINに変更して、もう少し柔軟性を高めることができます。

より詳細な例については、更新されたサインインドキュメントをご覧ください:https ://developers.google.com/+/mobile/android/sign-inおよびhttps://developers.google.com/+/mobile/android / people#retrieve_profile_information

于 2013-03-07T10:53:44.033 に答える
0

ここで説明されている手順に従って、デジタル署名された .apk ファイルの公開証明書を Google API コンソールに登録しましたか?

于 2013-03-08T01:46:01.957 に答える