Get Facebook user Events list and details in Android - facebook

new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/"+MainActivity.ME_FBUSER_ID+"/events",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
Log.e("event",response.toString());
Toast.makeText(getActivity(), ""+response.toString(), Toast.LENGTH_SHORT).show();
}
}
).executeAsync();
returns
{Response: responseCode: 200, graphObject: {"data":[]}, error: null}

Have you set Permissions? That for you have to set user_events permission. At user login time. as like below
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList("user_events", "friends_events"));
See below link for user permission:
https://developers.facebook.com/docs/facebook-login/android/permissions
https://developers.facebook.com/docs/facebook-login/permissions/#adding
You have to add permission after you can get it.
If you have done all above things and not work then you have to put app for review.
if you get Debug Message as like blow image in Graph API Explorer. You have to put app for review.
Documantation say To use the user_events permission you need to submit your app for review.
See below ScreenShot:

Your access token probably doesn't contain the user_events permission... Do you gather it during login?
See
https://developers.facebook.com/docs/facebook-login/permissions#reference-user_events

Related

Refresh Facebook access token

I am using the Facebook Login for Devices API to authenticate a device that only has a display where I want to display Page information.
I am able to authenticate fine and get an access token and display page information like I want but how do I refresh the access token that was given to me when the user put in the device code to allow the device by going to facebook.com/devices? I cant have the user do this every 60 days or whenever the token expires.
I have not found any documentation about how to refresh them other than saying that the native sdk's do it automatically. Can anyone point me to documentation or something where I can refresh access tokens?
After looking through the Facebook Sdk for Android I found that its a simple graph api call that you can make to extend an access token
private static GraphRequest createExtendAccessTokenRequest(AccessToken accessToken, GraphRequest.Callback callback) {
Bundle parameters = new Bundle();
parameters.putString("grant_type", "fb_extend_sso_token");
parameters.putString("client_id", accessToken.getApplicationId());
return new GraphRequest(
accessToken, TOKEN_EXTEND_GRAPH_PATH, parameters, HttpMethod.GET, callback);
}
Where TOKEN_EXTEND_GRAPH_PATH is oauth/access_token

How to update permissions for posting pictures to Facebook

I develop a game with unity3d, I've integrated facebook's unity3d-SDK.
At login, I used
public void LoginFB()
{
var perms = new List<string>() { "public_profile", "email","user_friends"};
FB.LogInWithReadPermissions(perms, AuthCallback);
}
But when I take a screenshot to post to facebook using :
FB.API("me/photos", HttpMethod.POST, ScreenshotSharePostCallBack, wwwForm);
The callback result said : 403 forbidden.
So I want to update the Permissions, but I have no idea about how to update it.
when I added the follow on the share button
FB.LogInWithPublishPermissions(new List<string>() { "publish_actions" }, callback : PublishActionsDone);
the app crashed.
Please tell me how to update the permissions when user click the button of sharing ,and how to open share dialog when using FB.API(.....).
Thanks !
This doens't work anymore. You have to use FB.ShareLink() now. which doesn't require any permission like "publish_actions" anymore. This now what Facebook prefers. BTW I forgot to mention you have to build it in order for it to work and see the results. :D
https://developers.facebook.com/docs/unity/reference/current/FB.ShareLink

facebook API: manage_pages permission is not working

I want to pull the list of pages from an account by using my App. I took reference from https://developers.facebook.com/docs/facebook-login/login-flow-for-web/v2.2
I have added few scopes "manage_pages, publish_stream, read_stream, publish_actions, publish_pages" to fb:login-button so that I can pull pages. I have added one more function
function getFacebookPages() {
FB.api('/me/accounts', function( apiResponse ) {
if( apiResponse && !apiResponse.error ) {
console.log('For Facebook pages');
console.log(apiResponse);
}
});
}
to pull pages, but it not pulling pages.
Please help me.
For permissions that aren't the default ones ( email, public_profile, user_friends ) you need in 'Status & Review'(from the menu in your app dashboard) to make a submission for them.
Until your review is completed you could create in your app a TEST app at 'Test Apps' ( again, from the menu in your app dashboard ). If you code using the ids of an test app you don't need the submission for permissions, just specify them in the scope.
This must work, please give more details if doesn't works

Info facebook read_stream permission

In my Java app (still in early development and with only a couple of java classes) I need to access to my wall posts (at the end i'll have to access to my customer wall posts) and list them; in order to do it, i need the read_stream permission
I followed the full instructions of facebook developers site; I submitted my review; the final result was that FB developers denied te read_stream permission; they wrote me this alert:
General
Your app appears to be a test submission. If your app is still
in development, please wait to submit it for review until it has full
functionality.
The following items were not reviewed due to general
issues with your app: read_stream
How can I have the read_stream permission? Any tip is really appreciated
EDIT START
I'm using spring-social; in my java code, when I use the method: facebook.feedOperations().getFeed() I access to home posts and I have no problem at all; when I use facebook.feedOperations().getHomeFeed() I try to access to my wall posts and I got the exception I posted
My Java code:
#Override
public PagedList<Post> getPosts() throws Exception
{
try
{
Facebook facebook = new FacebookTemplate(this.facebookClientToken);
if( proxyEnabled )
{
if( requestFactory != null )
{
((FacebookTemplate)facebook).setRequestFactory(requestFactory);
}
else
{
throw new IllegalArgumentException("Impossibile settare la requestFactory; proxy abilitato ma requestFactory null");
}
}
PagedList<Post> result = facebook.feedOperations().getHomeFeed();
result.addAll(facebook.feedOperations().getFeed());
return result;
}
catch (Exception e)
{
String messagge = "Errore nel recupero feed: "+e.getMessage();
logger.fatal(messagge, e);
throw e;
}
}
My StackTrace:
09:35:31,939 WARN [RestTemplate] GET request for "https://graph.facebook.com/me/home?limit=25" resulted in 403 (Forbidden); invoking error handler
{"error":{"message":"(#200) Requires extended permission: read_stream","type":"OAuthException","code":200}}
09:35:31,971 ERROR [CoMiSocialNetworkSvcImpl] Errore nel recupero feed: The operation requires 'read_stream' permission.
org.springframework.social.InsufficientPermissionException: The operation requires 'read_stream' permission.
at org.springframework.social.facebook.api.impl.FacebookErrorHandler.handleFacebookError(FacebookErrorHandler.java:116)
at org.springframework.social.facebook.api.impl.FacebookErrorHandler.handleError(FacebookErrorHandler.java:65)
regards
Angelo
If your app needs read_stream permission then you can stop development now - FB will not give you that permission. Go to the following page to see why:
https://developers.facebook.com/docs/facebook-login/permissions/v2.3#reference-user_posts
(search on "read_stream").

Facebook Ask new permissions

I've an application that only asks for "user_about_me". Now I want to ask for new permission (publish_stream) but the response object returns "connected" if the user ignores the new permission. Because I want to post to the user's wall I'll get an error when posting to the user's wall "The user hasn't authorized the application to perform this action".
How can I do this?
I'm using Javascript SDK.
Basically you have to handle all the possibilities for user permissions/authorization when a user logs in. Here is a simplified working example from some FB integration I have done:
FB.Event.subscribe('auth.login', function(response) {
if(response.status === 'connected'){
FB.api('/me/permissions', function(resp) {
if(resp.data[0].publish_stream){
//User has permissions and authorization
}
else{
//User has not enabled publish stream, ask them to enable permission
}
}
}
If they have the permissions, I show them their avatar/username and some other options. If not, I present a link that asks them for the required permissions when clicked.