Facebook Graph API comments filtering not working - facebook

I need to filter out a specific comment by its id using the post thread. I have tried these processes but failed.
https://graph.facebook.com/v12.0/{post_id}?fields=message,comments&filtering=[{'field':'id','operator':'IN','value':[{comment_id}]}]&access_token
returns all comments
https://graph.facebook.com/v12.0/103436852373094_146018341448278?fields=message,comments{id,message&filtering=[{'field':'id','operator':'IN','value':[{comment_id}]}]}
returns
{
  "error": {
    "message": "Syntax error \"Expected \"}\", got end of string\" at character 27: message,comments{id,message",
    "type": "OAuthException",
    "code": 2500,
    "fbtrace_id": "ASHThq8rIMxJztBRcwWS-I2
"
  }
}
did I missed anything?

Related

Get adset_schedule, bid_adjustments, bid_amount and bid_info for Ad Set

Referenced from the website:
https://developers.facebook.com/docs/marketing-api/reference/ad-campaign#fields
I used the following Graph URL to get the bid_info, bid_adjustments, adset_schedule, and bid_amount.
https://graph.facebook.com/v13.0/ad set id/?fields=name,adset_schedule,bid_adjustments,bid_amount,bid_info&access_token=accesstoken
I am getting the following response when I requested the above endpoint
{
"name": "NAT_NAT_SCV_CRP_SOC_RTG_RTR_A2564_NON_FACEBOOK INC_INM_NON_NON_CPA_|VV-to-3s-Retargeting-+-LAL-5\u0025|_FBP_1x1_NON_NON_N_Learn More_N_SSV",
"id": "6278021391491"
}
I am not getting adset_schedule,bid_adjustments,bid_amount,bid_info. Can anyone give a clear idea of how to get those values?

"(# 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

Need one help regarding fetching data value from response

Need one help regarding fetching data value from response.
Below is my response which I got after hitting URL.
{
"response": {
"Error Message": "Invalid Input missing",
"success": "false""
}
}
In this I want to read "Error Message" through POSTMAN test. For same reason I have written below code, but it is not working due to space between key.
var data = JSON.parse(responseBody);
tests ["Verify Error message"] = data.response.Error Message==="Invalid Input - Mandatory data(Company ID/source Id/SalesRep Ids/ContactPerson Ids) missing";
You're trying to use Error Message as a field with a space in it. Try:
tests ["Verify Error message"] = data.response.["Error Message"]==="Invalid Input - Mandatory data(Company ID/source Id/SalesRep Ids/ContactPerson Ids) missing";
This is not good to compare string.
In your response you must have like this,
{
"response": {
"Error Message": "Invalid Input missing",
"success": "false",
"responseCode" : 400
}
}
for more response codes, please go to this link,
http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
Then after do comparison,
var data = JSON.parse(responseBody);
if(data.reponse.responseCode == '400'){
// do stuff
}

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.