2013-07-25 99 views
3

我在android中開發了一個應用程序,在該應用程序中我從Facebook獲取用戶詳細信息。我能夠獲取用戶名,姓氏,姓氏,但電子郵件在某些Facebook帳戶中爲空。在某些Facebook帳戶中,我發現電子郵件ID和一些Facebook帳戶電子郵件爲空,原因是什麼在android中獲取Facebook用戶詳細信息

+0

因爲他們沒有進入或他們限制他人從他人的郵件。 – Karthi

回答

4

問題是電子郵件許可,這是獲取電子郵件ID的工作代碼。 這是我在這裏給出 Unable to access facebook login?

Session.openActiveSession(this, true, new Session.StatusCallback() { 

      // callback when session changes state 
      @Override 
      public void call(Session session, SessionState state, 
        Exception exception) { 
       if (session.isOpened()) { 
        // make request to the /me API 

        List<String> permissions = session.getPermissions(); 
        if (!isSubsetOf(PERMISSIONS, permissions)) { 
         pendingPublishReauthorization = true; 
         Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
           RegisterActivity.this, PERMISSIONS); 
         session.requestNewReadPermissions(newPermissionsRequest); 
         return; 
        } 
        Request.executeMeRequestAsync(session, 
          new Request.GraphUserCallback() { 

         // callback after Graph API response with 
         // user object 
         @Override 
         public void onCompleted(GraphUser user, 
           Response response) { 
          if (user == null) { 
           Toast.makeText(
             RegisterActivity.this 
             .getApplicationContext(), 
             "Facebook Error", 
             Toast.LENGTH_LONG).show(); 

          } else { 
           Toast.makeText(
             RegisterActivity.this 
             .getApplicationContext(), 
             user.getName() 
             + " Logged in Successfully.", 
             Toast.LENGTH_LONG).show(); 
           GraphUser abc = user; 

           id = user.getId(); 
           name = user.getName(); 
           gender = user.getProperty("gender") 
             .toString(); 
           editname.setText(name); 
           username.setText(user.getUsername()); 
           JSONObject jo = user 
             .getInnerJSONObject(); 
           Log.d("Details", jo.toString()); 
           try { 
            emailid.setText(user 
              .getProperty("email") 
              .toString()); 
           } catch (Exception e1) { 
            // TODO Auto-generated catch 
            // block 
            e1.printStackTrace(); 
           } 

           try { 
            location = user.getLocation() 
              .getProperty("name") 
              .toString(); 
           } catch (Exception e) { 

            e.printStackTrace(); 
           } 



          } 

          return; 
         } 

        }); 

       } 
      } 
     }); 

onActivityResult方法

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    Session.getActiveSession().onActivityResult(this, requestCode, 
      resultCode, data); 
} 

isSubsetoff()方法

private boolean isSubsetOf(Collection<String> subset, 
     Collection<String> superset) { 
    for (String string : subset) { 
     if (!superset.contains(string)) { 
      return false; 
     } 
    } 
    return true; 
} 

權限根據您的需要

private static final List<String> PERMISSIONS = Arrays.asList("email", 
     "user_about_me", "user_location"); 
+0

感謝阿布舍克...... –

+0

當我在我們的代碼中添加權限,然後我發現下面的錯誤.. –

+0

java.lang.RuntimeException:無法恢復活動{com.parkhya.treebidsale/com.facebook.LoginActivity}:com .facebook.FacebookException:無法使用空調用程序包調用LoginActivity。如果調用者的launchMode是singleInstance,則會發生這種情況。 –

相關問題