I am getting this error message while trying to open the facebook page of the user.The strange thing is that if I have a mutual friend with that user the page loads with no problem, but I don't think it's default behavior, otherwise I can't understand the meaning of user_link permission.
Facebook has approved user_link permission and I passed App Review.
From developer account I changed the API version the app calls to v3.1.
The way I am getting user_link
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("user_gender", "user_link"));
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
makeGraphRequest(loginResult.getAccessToken());
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
}
});
public void makeGraphRequest(AccessToken token) {
GraphRequest request = GraphRequest.newMeRequest(
token, (object, response) -> {
try {
userStorage.setUserProfileUrl(object.getString(AppConstants.LINK));
} catch (JSONException e) {
e.printStackTrace();
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "name,gender,link,picture.width(700).height(700)");
request.setParameters(parameters);
request.executeAsync();
}
And using this answer for opening the page.
Intent intent;
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=" + currentUser.getLink()));
context.startActivity(intent);
} catch (Exception e) {
intent = new Intent(context, FacebookWebViewActivity.class);
intent.putExtra(AppConstants.USER_LINK, currentUser.getLink());
context.startActivity(intent);
}
build.gradle
implementation 'com.facebook.android:facebook-login:4.33.0'
I will be very thankful if someone can suggest any solution. I faced this issue before the facebook new API version also.
From this post we can find the following bit of text
For most apps, links will only redirect to the individual's Facebook
profile for logged in people in the person's extended network.
So, I guess there is no way to be 100% sure that the user page will be loaded properly.
https://developers.facebook.com/docs/graph-api/changelog/version3.0#login
...the following fields that belonged to public_profile are deprecated...
As you can read in the changelog, the "link" and "gender" fields are deprecated.
Edit: But they have introduced new permissions user_link and user_gender so that users can explicitly asked for those particular fields. (Thanks to CBroe for pointing that out)
Related
I am getting this error message while trying to open the facebook page of the user.The strange thing is that if I have a mutual friend with that user the page loads with no problem, but I don't think it's default behavior, otherwise I can't understand the meaning of user_link permission.
Facebook has approved user_link permission and I passed App Review.
From developer account I changed the API version the app calls to v3.1.
The way I am getting user_link
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("user_gender", "user_link"));
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
makeGraphRequest(loginResult.getAccessToken());
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
}
});
public void makeGraphRequest(AccessToken token) {
GraphRequest request = GraphRequest.newMeRequest(
token, (object, response) -> {
try {
userStorage.setUserProfileUrl(object.getString(AppConstants.LINK));
} catch (JSONException e) {
e.printStackTrace();
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "name,gender,link,picture.width(700).height(700)");
request.setParameters(parameters);
request.executeAsync();
}
And using this answer for opening the page.
Intent intent;
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=" + currentUser.getLink()));
context.startActivity(intent);
} catch (Exception e) {
intent = new Intent(context, FacebookWebViewActivity.class);
intent.putExtra(AppConstants.USER_LINK, currentUser.getLink());
context.startActivity(intent);
}
build.gradle
implementation 'com.facebook.android:facebook-login:4.33.0'
I will be very thankful if someone can suggest any solution. I faced this issue before the facebook new API version also.
From this post we can find the following bit of text
For most apps, links will only redirect to the individual's Facebook
profile for logged in people in the person's extended network.
So, I guess there is no way to be 100% sure that the user page will be loaded properly.
https://developers.facebook.com/docs/graph-api/changelog/version3.0#login
...the following fields that belonged to public_profile are deprecated...
As you can read in the changelog, the "link" and "gender" fields are deprecated.
Edit: But they have introduced new permissions user_link and user_gender so that users can explicitly asked for those particular fields. (Thanks to CBroe for pointing that out)
Facebook just driving me crazy! I have no idea, what they are trying to get from me. The thing is that I want to is to make SHARE button inside my Android app. What code I should write in order to get similar window?
This is the pic what I wanna do:
http://s29.postimg.org/pvgbhv1dz/151020_0002.png
This is the code how I do it now:
case FB_ID:
FacebookSdk.sdkInitialize(getApplicationContext());
fbCallbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
LoginManager.getInstance().registerCallback(fbCallbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "FB");
openFragment(MakeWallPostFragment.newInstance(social_id,null), false);
// App code
}
#Override
public void onCancel() {
// App code
finish();
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
break;
This code give me this kind of error:
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions")); //this is the culprit string gives me:
The publish_actions permissions are missing,
the share will fail unless this app was authorized to publish in another installation. this error
What should I use to make it happen?
Btw, this is the video with explanation, but I think all this stuff is deprecated now:http://www.youtube.com/watch?v=iBBVkwBeaY4
I have a activity called StarterActivity which is the launcher activity of my android application. I have provided a logout menu option on press of which I am revoking all apps permissions. I verified all permissions are getting revoked and my app is no longer listed in https://www.facebook.com/settings?tab=applications
However the access token does not get cleared.
switch(item.getItemId())
{
case R.id.action_logout:
GraphRequest delPermRequest = new GraphRequest(AccessToken.getCurrentAccessToken(), "/{user-id}/permissions/", null, HttpMethod.DELETE, new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
if(graphResponse!=null){
FacebookRequestError error =graphResponse.getError();
if(error!=null){
Log.e(TAG, error.toString());
}else {
finish();
}
}
}
});
Log.d(TAG,"Executing revoke permissions with graph path" + delPermRequest.getGraphPath());
delPermRequest.executeAsync();
break;
}
I want to relaunch my StarterActivity Intent again on logout.
I added
startActivity(new Intent(getApplicationContext(),StarterActivity.class));
after clearing permissions. But neither AccessToken.getCurrentAccessToken() or Profile.getCurrentProfile() is null. Perhaps getting cashed?
I also tried
AccessTokenTracker accessTokenTracker = new AccessTokenTracker() {
#Override
protected void onCurrentAccessTokenChanged(
AccessToken oldAccessToken,
AccessToken currentAccessToken) {
Log.d(TAG,"Access token changed");
if (currentAccessToken == null){
//User logged out
startActivity(new Intent(getApplicationContext(),StarterActivity.class));
}
}
};
But none of them seem to work. Access token is not cleared. How can I invalidate this data if cashed? I was hoping for it to get cleared on revoking permissions? Or is there a neater way to logout?
I am using SDK 4.x. More details on perm - https://developers.facebook.com/docs/graph-api/reference/user/permissions
What finally worked was
LoginManager.getInstance().logOut();
What it internally does is setting each access token and profile to null
public void logOut() {
AccessToken.setCurrentAccessToken((AccessToken)null);
Profile.setCurrentProfile((Profile)null);
}
Just revoking permission will not do. You can either manually set token and profile as null or use above API.
I am able to access the id, firstname, lastname, gender, and email of a GraphUser by using the following code.
But, I also need access to "location", "number of friends", "basic info" and "work company". How can this be done? I have tried other stackoverflow links, and checked the Facebook SDK link, but not getting a break through. Could I be provided code to directly access the required fields in the same way as the data that I already have?
What other permissions would I need?
loginBtn.setReadPermissions(Arrays.asList("public_profile", "email", "user_friends", "user_birthday", "read_friendlists"));
loginBtn.setUserInfoChangedCallback(new UserInfoChangedCallback() {
#Override
public void onUserInfoFetched(GraphUser user) {
if (user != null) {
login_text.setText("Please login to continue");
userDetails = new JSONObject();
try {
Log.d("user birthday", user.getBirthday());
userDetails.put("fbId", user.getId());
userDetails.put("firstName", user.getFirstName());
userDetails.put("lastName", user.getLastName());
userDetails.put("gender", user.getProperty("gender").toString());
userDetails.put("email", user.getProperty("email").toString());
} catch (JSONException e) {
Log.d("Error: ", "Error setting user settings in FBActivity");
}
} else {
//login_text.setText("You are not logged");
}
}
});
EDIT:
I got everything except the total number of friends an individual has. How can that be done. I have gone through your links and it seems that I need to call another GraphRequest link. But I don't that. I want the total number of friends (no names, no details, just the number). I have added the permission "user_friends". What code should I write to get the number?
This is a pretty straightforward answer and the facebook documentation covers these details. https://developers.facebook.com/docs/reference/android/current .
https://developers.facebook.com/docs/graph-api
Here is the answer anyway!
You will need user_friends for the number of friends. It returns the total count of friends.
The default permission set called "basic info" has been removed, and replaced by "public profile".
user_location for location.
user_work_history for the work company.
please note : users can choose to not give these permissions to your app, in which case you should handle those scenarios properly, else your app will get rejected in the review process.
To get number of friends please refer to the following link:
https://developers.facebook.com/docs/graph-api/reference/v2.4/user/friends
Permissions needed would be: user_friends, which you already have included..
You'll get friends count in field 'summary' in the name of total_count
Similar question: facebook api on android - how can I get the number of friends that a user has?
loginBtn.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
new GraphRequest(
loginResult.getAccessToken(),
"/me/friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.i("response", response.getJSONArray().toString()); //find the summary 'total_count' in the response
}
}
).executeAsync();
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException exception) {
}
});
I managed to login to Facebook / get permissions.. retrieve friends data, names/ids etc.
The issue is that I cannot send an app invite to my friends. I'd like to send the invite without a dialog to a single person. But it seems that's wishful thinking. Now I'd settle for anything. It seems nothing will do the job!
I tried the dialog provided by Facebook Graph API but it tells me that the display is not supported (error 103). Also tried the fix modifying the url inside the Facebook SDK to not point to the mobile version and set the display as popup. Still no good (same error);
Any thoughts on this?
Thank you in advance.
(BTW, it seems to me like Facebook is a very unreliable service!)
This code will bring up an app invite dialog (and I don't know how to send an invite without a dialog). Note: assumes that facebook has been successfully authorized/logged in:
Facebook facebook = new Facebook( MY_APP_ID );
...
Bundle parameters = new Bundle();
parameters.putString( "message", "Check this out!" );
facebook.dialog( activity, "apprequests", parameters,
new Facebook.DialogListener()
{
public void onComplete() { ... }
public void onFacebookError( FacebookError e ) { ... }
public void onError(DialogError e) { ... }
public void onCancel() { ... }
} );