How to delete facebook post programmatically that has not been posted by your application? - facebook

How to delete Facebook post that is not posted by your application?
Using graph API - according to docs
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{post-id}",
null,
HttpMethod.DELETE,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
} ).executeAsync();
Above code is not working.
It is giving error:-
{
"error": {
"message": "(#200) This post wasn't created by the application",
"type": "OAuthException",
"code": 200,
}
}
Or does there exist some other method?

According to the Graph API reference:
An app can delete any post it published, or a page-management app can delete a Post published to a Page that the app manages.
So it depends on what you are doing.

Related

"(# 100) You must provide an application access token or user access token who owns or is the developer of the application" (see Description)?

I make a request to find out the data about my user access token:
fetch("https://graph.facebook.com/v8.0/debug_token?input_token=" + access_token).then(function (response) {
response.text().then(function (textII) {
alert(textII);
});
});
In this case, I take the accessToken value from auth Response after authorization to the application and Facebook:
{
status: 'connected',
authResponse: {
accessToken: '{access-token}',
expiresIn:'{unix-timestamp}',
reauthorize_required_in:'{seconds-until-token-expires}',
signedRequest:'{signed-parameter}',
userID:'{user-id}'
}
}
But I get an error:
{
"error": {
"message": "(#100) You must provide an app access token or a user access token that is an owner or developer of the app",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "AtpM_XaTOgH7YH-OXHdQCXj"
}
}
The value of my variable access_token is not null (I checked), while this is sort of a user access token (the keyword "sort of"). So what's wrong? Explain, please. If you need information about what I need it for, then I need it for this request:
for (var iio = 0; iio < posts_ids.length; iio++) {
fetch("https://graph.instagram.com/" + posts_ids[iio] + "?fields=id,media_type,media_url,owner,timestamp&access_token=" + access_token).then(function (response) {
response.text().then(function (textII) {
alert(textII);
});
});
}
Which throws an error:
{
"error": {
"message": "Invalid OAuth access token.",
"type": "OAuthException",
"code": 190,
"fbtrace_id": "AD7BAPqUGdQGC6dyV9K_FFr"
}
}
At the same time, in my previous requests, just starting with "https://graph.facebook.com/", and not "https://graph.instagram.com/", everything worked with the accessToken that I received after registration.
Help me please. I'm new to the Instagram API, so I can be pretty dumb.
Please turn off the setting(Setting -> Advanced -> Application authentication), it works!
#Denis Bredun , you would have to pass access_token field also as the URL param, so just update the url to -
https://graph.facebook.com/v8.0/debug_token?input_token=<access_token>&access_token=<access_token>
Try resetting your app secret. I was getting the same problem, and this fixed it.
I solved the error by changing the app secret to the correct one.
Make sure you are using the proper app secret.
For me, using the debug_token api requires the "page token" and the "app token" and then you call the api in the format :
https://graph.facebook.com/v<version>/debug_token?input_token=<page_token>&access_token=<app_token>
As per the facebook doc To get the app_token, you need the app id and app secret. And then you call https://graph.facebook.com/oauth/access_token?client_id={your-app-id}&client_secret={your-app-secret}&grant_type=client_credentials
To get the page_token, this is done by first getting the user_token, then you convert the user_token into a long lived user token, and then you get the page token calling the api "/<page_id>?fields=access_token".
Note that you will need the proper permissions on the user_token to do that, like "pages_read_engagement" otherwize you will get an error from the api trying to get the page token.

Can a Facebook page message a user without the user first sending a message to the page?

I'm wanting to set up an app for a page(or possibly group) where if a user comments on the page then the page will send the user a private message. So far I'm finding this to be impossible, I'm trying to make the following call via postman:
POST https://graph.facebook.com/v3.2/me/messages
{
"recipient": {
"id": "{receipientId}"
},
"message": {
"text": "hello, world!"
}
}
The error message I'm getting back is:
{
"error": {
"message": "(#551) This person isn't available right now.",
"type": "OAuthException",
"code": 551,
"error_subcode": 1545041,
"fbtrace_id": "{fbtrace_id}"
}
}
I've seen this functionality with another app and I can't seem to find the documentation anywhere that allows this type of behavior, any assistance would be greatly appreciated.
Edit: The recipient id is coming from a page scoped user id.
Ok through more reading I was able to find the answer. Private replies are how to do this.
Send a post to this endpoint:
https://graph.facebook.com/v3.2/{CommentId}/private_replies
{
"message": "Hello, world"
}
Documentation: https://developers.facebook.com/docs/graph-api/reference/v3.2/object/private_replies

Share an image to Faceboook

I need to share an image to facebook. For this I am trying the API call suggested here
FB.login(function(response) {
if (response.authResponse) {
FB.api(
"/{page-id}/photos",
"POST",
{
"url": "https:\/\/www.facebook.com\/images\/fb_icon_325x325.png",
"published": "false"
},
function (response) {
if (response && !response.error) {
console.log(JSON.stringify(response))
/* handle the result */
}
else
{
console.log("ERROR: " + JSON.stringify(response))
}
}
);
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
But I am getting an error (#803) Some of the aliases you requested do not exist: {page-id}
Is page-id the same as the userID returned in the authResponse? Because I also tried hardcoding that id, but I got a deprecated API message.
I need to allow the user to share the photo directly to his feed.
Thanks
Page ID and User ID are not the same. You get a User ID after authorization, you get a Page ID by using the /me/accounts endpoint with a User Token. You can also get Page Tokens with /me/accounts?fields=access_token. You need to use a Page Token with the publish_pages and manage_pages permissions to create posts or photos on a Page you manage.
As WizKid commented, you can also just use /me/photos to upload photos. Just use a Page Token.
More information: https://developers.facebook.com/docs/facebook-login/access-tokens/

Cakephp 2.x get message { "name": "The request has been black-holed", "url": "\/rest_sms_boxs.json" } in Restfull api

I write a controller and it contain multi POST action but whene i post data to these actions my response is :
{ "name": "The request has been black-holed", "url": "/rest_sms_boxs.json" }
Now how can i resolve this problem.
Certainly the security mode.
Try in your controller:
public function beforeFilter()
{
parent::beforeFilter();
$this->Security->unlockedActions = array('your_method');
}

Retrieve Facebook Post Comments Using Graph API

I tried to get Facebook comments using:
http://graph.facebook.com/[post_id]/comments
It results only 2 of 15 comments, and without count info.
{
"data": [
{
"id": "[post_id]",
"from": {
"name": "[name]",
"id": "[id]"
},
"message": "[message]",
"created_time": "2011-01-23T02:36:23+0000"
},
{
"id": "[id]",
"from": {
"name": "[name]",
"id": "[id]"
},
"message": "[message]",
"created_time": "2011-01-23T05:16:56+0000"
}
]
}
Anyone know why only 2 comments?
Also, I want to retrieve comments (default number) or retrieve comments with my limit number, and get its comments count. Any idea? (Please use Graph API).
You need to call it from a secure request https and provide an access_token:
https://graph.facebook.com/19292868552_118464504835613/comments?access_token=XXX
EDIT:
Added the object from the post document. try clicking the comments connection and then remove the access_token and try and see the difference.
In order to get the Like count and the comment count then you need to use a combination of the PostOwnerID and PostID not just the PostID
So for your example it would be:
https://graph.facebook.com/153125724720582_184234384932460/comments
Again, as mentioned in some of the other answers you need to use the https method along with an auth_token
I experienced the same problem with comments. The issue was that I was using an access token for a test user. Because test users don't have access to other FB users information, only the comments from pages were shown.
There is a word JUGAAR in Urdu that means, finding a way out, just to get the job done. So for like purpose I made this JUGAAR, I hope it helps.
$contents = file_get_contents("http://graph.facebook.com/" . $_GET['id'] . "/likes");
if (substr_count($contents, 'name')>0) {
echo substr_count($contents, 'name') . " people like this album";
}
By the way I am also new to this Fb stuff, I am looking for help to post comments. When I try to use graph.api./id/comments?access_token=sdfsfsdf&message="D" it still returns comments for the id instead of posting.
As a sanity check, do you have "read_stream" permission? I can see the full comments with my access token that uses "read_stream". As mentioned by other people, you have to use https and access token as well...
Try to authenticate via App Login (http://developers.facebook.com/docs/authentication) and then to call GraphAPI with access_token prarameter.
You can do something like this to avoid the whole count of comments issues:
Get the object's (a post is considered an object in the Graph API) ID-as I understand from your question, you already have it?
Create a Comments Social Plugin with this ID, and get the code for it.
Embed the code in your site.
This will result in all the comments for this object.
To get the count of comments per object, you can execute an fql query, something like this:
SELECT comments FROM stream WHERE post_id = [yourpostid]
This will return in the comments array under the count parameter the number of counts for this object.
SELECT comments FROM stream WHERE post_id = [yourpostid] shall not work in this case ..
the id which is returned after making a graph call successfully to post on a user's wall (using access_token of an application ) is of the form abcdef_qwerty ( underscore seperated id )
where as the post id which is mapped in the post_id of the comments table is of the form "lmnop" ..
to get the counts of like and comments on this post id of form "abcdef_qwerty" making a graph call withh app generated access token seems to be the only solution ..
something like:
https://graph.facebook.com/100002619172565_117323155031656?access_token=xxxxxxxxxxxxx
After Successfully Login call this method facebookComments()
parameters.putString("fields", "message"); .............// Its Important
AccessToken accessToken = AccessToken.getCurrentAccessToken();
public void facebookComments() {
try {
getFriends(accessToken, new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.e("keshav", "one" + response);
CommonMethod.showAlert("res --> " + response, MainActivity.this);
}
}
);
} catch (Exception e) {
CommonMethod.showAlert("Exception is -> " + e, MainActivity.this);
}
}
public void getFriends(AccessToken token, GraphRequest.Callback callback)
{
// TODO Comments Working but id return only
GraphRequest requestt = new GraphRequest(token, "744511125731315_751199848395776/comments",
null, HttpMethod.GET, callback);
Bundle parameters = new Bundle();
parameters.putString("fields", "id"); // todo in use imp
parameters.putString("fields", "name"); // todo in use imp
parameters.putString("fields", "from"); // todo in use imp
parameters.putString("fields", "message"); // todo in use imp
requestt.setParameters(parameters);
requestt.executeAsync();
}
It results only 2 of 15 comments
Add a limit parameter to the URL:
http://graph.facebook.com/[post_id]/comments?limit=1000&access_token=XXX
This should show all the comments.