1
서클 친구의 이메일 목록을 가져와야하는 애플리케이션을 만들고 있습니다.Android에서 Google Plus의 친구에게 이메일 보내기
다음 코드를 시도했지만 작동하지 않습니다.
final String account = Plus.AccountApi.getAccountName(mGoogleApiClient);
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
HttpURLConnection urlConnection = null;
try {
URL url = new URL("https://www.googleapis.com/plus/v1/people/me");
String sAccessToken = GoogleAuthUtil.getToken(GooglePlusActivity.this, account,
"oauth2:" + Scopes.PLUS_LOGIN + " https://www.googleapis.com/auth/plus.profile.emails.read");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Authorization", "Bearer " + sAccessToken);
String content = CharStreams.toString(new InputStreamReader(urlConnection.getInputStream(), Charsets.UTF_8));
if (!TextUtils.isEmpty(content)) {
JSONArray emailArray = new JSONObject(content).getJSONArray("emails");
for (int i = 0; i < emailArray.length(); i++) {
JSONObject obj = (JSONObject)emailArray.get(i);
// Find and return the primary email associated with the account
System.out.println(obj.getString("value"));
Log.d("jai ho", "jai ho"+obj.getString("value"));
if (obj.getString("type") == "account") {
return obj.getString("value");
}
}
}
} catch (UserRecoverableAuthException userAuthEx) {
// Start the user recoverable action using the intent returned by
// getIntent()
startActivityForResult(userAuthEx.getIntent(), RC_SIGN_IN);
return account;
} catch (Exception e) {
// Handle error
// e.printStackTrace(); // Uncomment if needed during debugging.
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
}
도와주세요. 누구든지 좋은 모범이 있다면 여기에 게시하십시오. 친구 이메일을받을 수 있는지 알려주세요. 오랫동안 인터넷 검색을하지는 않았지만 정확한 정보를 얻지는 못했습니다.