How to send FB notifications using restfb api? - facebook-graph-api

I am trying to send fb notifications to users but getting the following exception
Exception in thread "main"
com.restfb.exception.FacebookGraphException: Received Facebook error
response of type GraphMethodException: Unsupported post request.
Object with ID '1543026015991325' does not exist, cannot be loaded due
to missing permissions, or does not support this operation. Please
read the Graph API documentation at
https://developers.facebook.com/docs/graph-api (code 100, subcode
null) at
com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:1197)
at
com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:1112)
at
com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1053)
at
com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:964)
at
com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:444)
at
com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:469)
at FacebookIntegrator.main(FacebookIntegrator.java:33)
Please find the code below:-
FacebookClient facebookClient1= new DefaultFacebookClient(app_access_token);
FacebookType publishMessageResponse1 = facebookClient1.publish(user.getId()+"/notifications", FacebookType.class, Parameter.with("template", "RestFB"));

That ID is not a User ID, it belongs to a Page. You can´t send notifications to Pages, you can only send notifications to Users who authorized your App.
Test: http://www.facebook.com/1543026015991325

Related

How to create a bot that automatically responds to comments and sends messages to customers on your Facebook page

I want to develop a chatbot that can trigger when a user comments on a post on the page, then it will automatically reply and send a message to that user.
I'm referencing the following facebook documentation but it doesn't seem right
https://developers.facebook.com/docs/permissions/reference/pages_read_user_content

Is it possible to send and fetch Facebook messages using Graph API for v4.0 or greater?

I want to create a web application using PHP which will allow to connect Facebook accounts with my application and once they authenticated my application can fetch inbox messages of that user and can auto reply to the messages received against authenticated Facebook accounts.
Also, allow user to send messages manually from my application to Facebook inbox.
Is this possible with Graph API or any other Facebook API which will allow me to do above mentioned things.
Some people was told that this feature is no longer available after Facebook Graph API v2.4.
and once they authenticated my application can fetch inbox messages of that user and can auto reply to the messages received against authenticated Facebook accounts.
Neither of those two things is possible.
You can not read the messages of user accounts any more, and you can not reply in their name either.
The only messaging that can be handled via API, is that between a user and a page.
Assuming you refer to Page conversations, not user conversation, see /conversations and /messages docs here:
https://developers.facebook.com/docs/graph-api/reference/page/conversations/
https://developers.facebook.com/docs/graph-api/reference/v5.0/conversation/messages

Instagram Graph API

My task is to get photo data of my business Instagram account with Instagram Graph API. I followed the instruction from Instagram Graph API -
https://developers.facebook.com/docs/instagram-api/reference/user/media
, which said request like
GET http://graph.facebook.com/17841405822304914/media
can get photo data from the Instagram account linked to the FB account in JSON format.
I tried to send GET request /my_facebook_id/media as said by the document with Graph API Explorer on FB developer platform but it failed to return the data I want.
This is the error I got:
message: Tried accessing nonexisting field (media) on node type (User)
type: OAuthException code: 100
Does the message mean the media field doesn't exist in the FB user?
What is the meanIng of error code 100? I can't even see that in FB official document.
I tried to use the Instagram business account ID for this request but I got an error message said the user object doesn't exist
How to get the task done? Thanks!
I guess you have missed creating a Facebook business page and linking your Instagram Business account to it.
Here is the guide to setup : https://developers.facebook.com/docs/instagram-api/getting-started
If this was done correctly and still you're facing the error is because of a Facebook bug where your account doesn't get linked correctly.
Here : https://developers.facebook.com/support/bugs/177912116363088/?disable_redirect=0
Solution : Please disconnect your Instagram account from your page. Then, on Instagram app, in setting you will have to switch back to personal account and reconvert to a business account
Note : Switching to a personal account you will lose the insights of your media.
Once this is done you should be able to get instagram_business_account and post which you can run your query to fetch the media :
GET http://graph.facebook.com/you-instagram-business-account-id/media

How to read inbox of Facebook pages using Graph API

Hi I'm developing management system for Facebook pages.
All Facebook pages are changed to sytle of timeline by the end of March, they will come to receive message from users.
So I want to add to read inbox of Facebook page, but I can't find how to read it by Graph API. ("/inbox" method is not worked with page access token.)
Please let me know how to do if you know.
Thanks,
Ogawa
I have suffered alot to find the correct url. It is totally different url compare to Profile messaging.
You can read the messages for a page by issuing an HTTP GET request to http://graph.facebook.com/PAGE_ID/conversations with a Page Access Token and read_mailbox permission.
Surprisingly you can reply for page messages also.
You can reply to a user's message by issuing an HTTP POST to http://graph.facebook.com/CONVERSATION_ID/messages
Note that a page can only reply to a user's message. It cannot initiate a private message with a user. Also, a page can respond not more than twice to a user's message before the user has replied back.
Hope that helps.
Graph api explore use this script after authenticating user, permission required
permission script:
$loginUrl = $facebook->getLoginUrl(array(
'scope'=>'email,read_mailbox,read_requests',
));
READ INBOX:
<?php
$user_mail=$facebook->api('/me?fields=id,name,inbox.limit(10)');
echo'<pre>',print_r($user_mail),'</pre>';
?>

Do I need publish_stream scope to delete invitation requests?

I'm using FB.ui({method: 'apprequests', ... }) to let users invite their friends to my java web app.
In the Facebook Requests Dialog documentation it says that I need to delete the request when the user has accepted the request:
When a user is directed to your application, by clicking a Request
from the application, the games dashboard, or from a Request
notification, you must delete the request after it has been accepted.
Requests are not automatically deleted once they have been clicked,
thus it is the developer’s responsibility to clear them once they have
been consumed.
http://developers.facebook.com/docs/reference/dialogs/requests/#deleting
When I try to do this with the RestFB Graph API Java client I get a permission error from facebook.
The code:
FacebookClient client = new DefaultFacebookClient(appAccessToken, new DefaultWebRequestor(), new DefaultJsonMapper());
client.deleteObject(String.format("%d_%d", requestId, facebookUserId));
The log says:
(com.restfb.DefaultWebRequestor) INFO: Executing a POST to
graph.facebook.com/XXX_XXX with parameters (sent in request body):
method=delete&access_token=XXX&format=json&locale=en_US
The error:
Facebook responded with HTTP status code 403 and response body:
{"error":{"message":"(#200) Permissions
error","type":"OAuthException"}}
I have tried both app access token and receiving user's access token, and I have scopes email and publish_actions. I read somewhere that I may need the publish_stream scope. I would rather not ask my users for that just to be able to delete requests, though? Or is it something else I'm doing wrong?
You don't need the publish_stream scope if you use the APP Token.
If you use the C# facebook SDK you can use this:
var fb = new FacebookClient(Config.FacebookAppId, Config.FacebookAppSecret);
var result = fb.Delete(string.Format(
"{0}_{1}?access_token={2}",
facebookRequestId,
facebookUserId,
fb.AccessToken
));
(See also: Facebook Deleting Requests)