问题
I am using facebook sdk 3.5 in native Android. This is how i get the id/name of my facebook freinds:
private void onSessionStateChange(final Session session,
SessionState state, Exception exception) {
System.out.println("onSessionStateChanged");
if (session != null && session.isOpened()) {
if (state.equals(SessionState.OPENED_TOKEN_UPDATED)) {
tokenUpdated();
} else {
getUserRequest(session);
getFriendsRequest(session);
}
} else {
profilePictureView.setProfileId(null);
userNameView.setText("");
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(getActivity(), requestCode,
resultCode, data);
// uiHelper.onActivityResult(requestCode, resultCode, data,
// nativeDialogCallback);
}
private void getFriendsRequest(Session session) {
session.requestNewReadPermissions(new NewPermissionsRequest(
getActivity(), PERMISSIONS));
final ProgressDialog dialog = new ProgressDialog(getActivity());
// get friends details
Request request = Request.newMyFriendsRequest(session,
new Request.GraphUserListCallback() {
@Override
public void onCompleted(List<GraphUser> users,
Response response) {
// if no errors
if (response.getError() == null) {
if (users != null) {
for (GraphUser user : users) {
FacebookFriend fb = new FacebookFriend(user
.getId(), user.getName(), "", "",
"", 0);
friends.add(fb);
}
....
}
}
The response is now:
{Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[{"id":"213","name":"Test name"}]}}, error: null, isFromCache:false}
All great here, but details like email(if shared), location, username are not in :
GraphObject{graphObjectClass=GraphUser, state={"id":"60711232217","name":"Test"}}
Where should i set permissions? This is my request:
{Request: session: {Session state:OPENED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[email, user_location, user_friends, friends_location, basic_info]}, appId:111111}, graphPath: me/friends, graphObject: null, restMethod: null, httpMethod: GET, parameters: Bundle[{access_token=dasdasdasdasdsada, format=json, sdk=android, migration_bundle=fbsdk:20130708}]}
Where should i add those permissions to have more details?
Thank you.
回答1:
Go to this link Graphapilink
Click the Graph API Explorer icon-> Then select your application name "YourApplication"-> Then click the GetAccesTocken .it show the Select Permission Pop Up window.->Then you select the Extended Permission tab.
Finally you will be select the necessary permission you want as the picture above
回答2:
- Facebook doesn't allow apps to access friends emails
For the Rest See The Below Images.. You have to set the right permissions and see how it works in my profile
And The result you will get
回答3:
Your query:
"me/friends?fields=id,name,location,email"
That means you are trying to fetch name, location, email. You can get the name, but for the location you need the permission friends_location
; for email- facebook dont allow you to fetch the email of the friends.
I hope i don;t have to create a request for each of my friends to get data
Of-course not. Your query is right, you'll get an array in the result just like-
{
"data": [
{
"name": Friend1_Name,
"location": {
"id": Friend1_LocationID,
"name": Friend1_Location
},
"id": Friend1_ID
},
{
"name": Friend2_Name,
"location": {
"id": Friend2_LocationID,
"name": Friend2_Location
},
"id": Friend2_ID
},
....
....
]
}
Live Demo
If you're getting-
"An active access token must be used to query information about the current user.","type":"OAuthException"
That means the (current) user has not logged into your app, or the session is expired. So, login/auth the user then make the API call.
来源:https://stackoverflow.com/questions/18781686/error-retrieving-email-and-location-from-facebook-request-in-android