Bad Request/Method not Implemented Error when Publishing Actions to the Timeline - facebook

I am working on a Joomla site and using myApi to handle most facebook integrations. The like button is working fine and picking up information from the og meta tags inserted by myApi.
On the website, the user can login using facebook - I have added the publish_actions permission to the myApi code, and I know this is being requested because when authorising the app, the oauth dialog says that actions like ordering from restaurants (the action i added to my fb app) will be posted to the timeline.
now, while ordering, I check whether the user has an entry in the myApi user table and if so, I provide a checkbox that lets the customer choose whether she wants the order action posted to her timeline. if ticked, I then use curl to try and post the order action to facebook. I have been using my account to test - I have authorised the app with all permissions requested. I use the myApi interface to get my user access token. I am adding the access_token and object url to the url as querystring parameters and then posting to it through curl.
The curl response I get is:
<HTML><HEAD>
<TITLE>400 Bad Request</TITLE>
</HEAD><BODY>
<H1>Method Not Implemented</H1>
Invalid method in request<P>
</BODY></HTML>
the response I get when going to the generated url in my browser is
{
"data": [
],
"paging":{
"next": "https://graph.facebook.com/me/og_collegekhana:order_from?restaurant=http\u00253A\u00252F\u00252Fwww.collegekhana.com\u00252Fstates\u00252Ftamil-nadu\u00252Fcampus-1\u00252Feat-1&access_token=[the token I got]&offset=25&limit=25"
}
}
I checked the object id of the url using
https://graph.facebook.com/?ids=http://www.collegekhana.com/states/tamil-nadu/campus-1/eat-1
I am not getting an object id. instead I get
{
"http://www.collegekhana.com/states/tamil-nadu/campus-1/eat-1": {
"id": "http://www.collegekhana.com/states/tamil-nadu/campus-1/eat-1"
}
}
I am completely lost and hope someone can tell me what I am doing wrong.

The problem was that instead of doing a cURL POST, one has to add the querystring parameter
method=post to the URL.

Related

How to display "from" fields in comments via Facebook Graph API

I would like to find the id (app-scoped) for someone who has posted a comment on a public page.
For example, I get a list of recent posts/comments on the NY Times page via:
v2.11/nytimes/feed?fields=comments.limit(10){message,created_time,from},name,message,from&limit=2
The data returned looks like this:
"comments": {
"data": [
{
"message": "Wouldn’t know. Not paying $13/mo for this.",
"created_time": "2017-12-10T05:57:18+0000",
"id": "10151412260164999_10151414049324999"
}
],
There is no from field. The same is also true if I attempt to view the comment directly using it's id with
v2.11/10151412260164999_10151414049324999?fields=from,message,created_time
I have tried using the Facebook Graph API Explorer, using both my User Token, as well as an App Token.
Since v2.11 of the Graph API, you need a Page Token to get user data of comments: https://developers.facebook.com/docs/graph-api/changelog/version2.11#gapi-90
User information will not be included in GET responses for any objects owned by (on) a Page unless the request is made with a Page access token. This affects all nodes and edges that return data for objects owned by a Page.
In other words: You can only get user information if you manage the Page.
Edit: Since the latests update in the Graph API, you have to get the App reviewed and you must go through Business Verification or Individual Verification. (thanx #Guiman04)
Please check whether you are using the accessToken for the page you are trying to get data from, i had same issue, and was resolved by using the correct accessToken for the page.

Facebook Graph API URL Scrape Inconsistent

I am running queries against Facebook Graph API to fetch OG meta information about URLs. Using a Facebook APP token, I can request most URLs and get their corresponding meta data back. But I have run into two issues that I can't find a solution for. I have one domain that refuses to pull any meta information using an APP token. Instead I get back an error 100 (Unsupported post request). But when I make the same request using a User Access Token, it works correctly. The second issue I found is that when a URL has any kind of OG error, Facebook is still scraping it, but will return a 100 error instead of returning the meta details (with both the app token and the user access token). I've even tried running the query without the scrape parameter, to no avail.
Normal Request That Returns Meta Fields of URL:
POST:
https://graph.facebook.com/v2.9/
{
"id": "http://viralcrunch.com/articles/22325/these-guys-invented-the-anti-smart-phone-and-it-will-blow-your-mind",
"scrape": "true"
}
Request That Returns 100 Unsupported post request Error W/ App Token
POST:
https://graph.facebook.com/v2.9/
{
"id": "http://turnthispage.com/dads-totally-winning-fatherhood/",
"scrape": "true"
}
Request That Returns 100 Invalid Object Error W/ Any Token
POST:
https://graph.facebook.com/v2.9/
{
"id": "http://www.thesportster.com/basketball/top-20-nba-players-who-live-life-to-the-fullest/",
"scrape": "true"
}
The second URL seems to be associated with an app id of an app that has some kind of access restrictions set; so I guess it is the same here as if you tried to access information about a Facebook Page that has access restrictions set - you can not query any details about those using the app access token, you need to use a user access token for a user that is allowed to see the content, or a page access token for that page.
And that you get an error response for the third one seems only natural. After all, this is a tool intended to debug and scrape the Open Graph objects you are in control of, so if the OG meta data is not in order it should return an error.

Facebook graph api like an external url, statistics

I am using a Facebook graph api to like an external url:
Method: POST
URL:
https://graph.facebook.com/v2.1/{userId}/og.likes
Header:
application/x-www-form-urlencoded
Body:
access_token={appId}|{appSecrect}&object={"url":"{myUrl}", "title":"{myTitle}"}
It is publishing successfully, returning an Action Id.
I have 2 problems:
I can keep liking with the same user Id and it will always succeed.
I can find my url in object_url table, but link_stat and url_like do not contain any information about this url.
Another strange thing, is if I publish my url like this:
access_token={appId}|{appSecrect}&object={myUrl}
The first request throws an error "title is missing".
The second time the same request returns success.
After that for the same requests it is able to distinguish that a user already liked the url. And I have information in link_stat table.
I finally found the solution.
1. Create an object
This request creates an object "link" and returns an Object Id.
URL: /app/objects/website
Header: Content-Type: application/x-www-form-urlencoded
Body: UrlEncode object's json!
access_token={appId}|{appSecret}&object={
"title":"Happy event",
"image":"{img_url}",
"url":"{custom_url}",
"description":"{description}",
"data": {} }
You can read more here:
https://developers.facebook.com/docs/opengraph/using-objects
2. Like an object
This request will "like" your link on behalf of the user.
It will show in the user's timeline as "User likes a link on you Application site..".
Make sure:
1. User has granted "publish_actions" permission;
2. Your application is apprved for submission of the likes. Otherwise only administrators, developers and testers of you Application can make "likes".
For more information read this :
https://developers.facebook.com/docs/opengraph/submission-process
URL: /v2.1/{user_id}/og.likes
Header: Content-Type:application/x-www-form-urlencoded
Body: object={object_id}&access_token={appId}|{appSecret}
3. Get likes for an object
URL: /v2.1/{object_id}/likes?access_token={appId}|{appSecret}

Posting on user's timeline on the behalf of the user

I created and APP on the Facebook.
Now I am trying to post a comment on the user's timeline using the Graph API but I cannot undestand what I need to do.
I already authorized the Application (I authorized this permissions: 'user_status,publish_stream,user_photos,email').
If I look on my profile -> privacy I can see that the APP can:
This app can: Post on your behalf
This app may post on your behalf, including status updates, photos and more.
Last data access:
Basic InformationToday
See details · Learn more
Posts on your behalf:
Who can see posts this app makes for you on your Facebook timeline?
Public
Notifications:
When to notify you?
The app sends you a notification
So this part seems OK.
On my application I do the following to try to post somenthing on my timeline (I need to post it when I am off line).
1) GET : https://graph.facebook.com/oauth/access_token?client_id=APPID&client_secret=*APP_SECRET*&grant_type=client_credentials
RESPONSE:
access_token = 422828347771671|UdQELQIf0N7krF4JUo7VwtPLTkk
2) GET: https://graph.facebook.com/search?q=myemail&type=user
RESPONSE:
_"error":_{
______"message":_"A_user_access_token_is_required_to_request_this_resource_",
______"type":_"OAuthException",
______"code":_102
___}
But reading the documentation (https://developers.facebook.com/docs/reference/api/#searching) it seems that this request does not need any kind of access token.
I also tried to add the access token, but the result is still the same.
3) I know my facebookid so I tried to use it directly:
POST: https://graph.facebook.com/100001139132403/feed
ARGUMENT:
access_token=422828347771671|UdQELQIf0N7krF4JUo7VwtPLTkk,
message=Hello
RESPONSE:
"error": {
"message": "(#200) This API call requires a valid app_id.",
"type": "OAuthException",
"code": 200
}
}
So I tried to add client_id=APPID and app_id=APPID, I tried to put one, the other and also both arguments as GET or POST but nothing changed.
I checked the APPId ad it is correct.
Do someone have any idea?
Thank you!
You cant simply generate a user access_token by querying to a URL. What you did gives the App access token and as the error say, you are trying to do something, that needs user access_token.
Refer and implement this : https://developers.facebook.com/docs/howtos/login/server-side-login/
And use that access_token for the rest of the processes.

Facebook JS SDK throwing 104 error when attempting to delete a app request

I have setup the facebook javascript sdk to initialize a friend invite dialog to send requests to friends. Clicking on the invite in Facebook, brings the user back to the site.
The query string has any and all request_ids that have not been handled (deleted).
I am following the documenation listed at the FB developers site here which states:
JavaScript SDK:
FB.api(requestId, 'delete', function(response) {
When they are returned to my site, the querystring has a request_ids parameter:
example: www.mysite.com/somepage?request_ids=0493834050
my Javascript code looks like this:
FB.api(requestIds[i], 'delete', function (response) {
console.log(response);
});
But the error I get is:
ERROR
code: 104
message: "An access token is required to request this resource."
type: "OAuthException"
All I want to do is delete the request ID. before I was even running the above code, the querystring was building up with every submitted request. It does appear they have been removed, because the querystring is reduced down to a single request id. But I am still uncertain it has been handled properly.
NOTE I am not using the Graph version - as I have not setup Graph on the app settings in Facebook.
I have the Facebook C# sdk - if someone has an easy way to do this here. I have tried the following with the same results.
var fbClient = new FacebookClient(accessToken)
fbClient.Delete(requestId);
I don’t see what’s possibly unclear about the error message – you need a valid access token to be able to delete requests, but by the looks of it you don’t have one.
So you’ll either have to have the user connect to your app in order to get an active access token for him; or you have to do it using your own app access token (but that’d have to be done server-side then, because you don’t want to transfer your app access token to the client side).