2015-01-12 4 views
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(); 
       } 
      } 

도와주세요. 누구든지 좋은 모범이 있다면 여기에 게시하십시오. 친구 이메일을받을 수 있는지 알려주세요. 오랫동안 인터넷 검색을하지는 않았지만 정확한 정보를 얻지는 못했습니다.

답변

0

모든 G + 계정의 모든 Google 이메일을 수신하려면 모두 동일한 애플리케이션이 있어야하지만 Google은이를 허용하지 않습니다. 인증하는 사용자의 경우에도 전자 메일 범위를 추가 할 때까지 전자 메일을 보유 할 수 없기 때문에 사용자가 전자 메일을 응용 프로그램에 허용하도록 허용 할 수 있습니다.

관련 문제