FaceBook FQL Query Not Working - facebook

We have used the v2.0 graph API & FQL(FaceBook Query Language) for getting the FaceBook details in our project. But recently the result is empty.
I have checked the developer.facebook.com and i found one solution that is Login Review process. We need to get the FB details means we need to get the pre approval from FB.(user_photos, user_videos) It'll work perfectly or not ?
https://developers.facebook.com/blog/post/2015/04/28/april-30-migration/
Sample Code :
args = "SELECT uid,name FROM user WHERE uid = me()"
file = urllib2.urlopen("https://api.facebook.com/method/fql.query?" + urllib.urlencode(args), timeout=3)
Please give some suggestion to fix this problem.
https://developers.facebook.com/docs/apps/api-v1-deprecation
Advance Thanks :)

Have a look at
https://developers.facebook.com/docs/apps/changelog#v2_1_deprecations
The FQL and REST APIs are no longer available in v2.1: Previously announced with v2.0, apps must migrate to versioned Graph API calls starting with v2.1.
You're querying the REST API which is deprecated, as cited. Use https://graph.facebook.com/fql instead.

Related

How to get Share_count and like_count in GraphAPI2.0

Getting notification from FB, they will remove FQL inthe later release after 2.0 which is expect to be on 2016.
Currently my Apps are using FQL to get the like_count and share_count. I hope someone can share with me how to achieve this in GraphAPI2.0 because in GraphAPI, I only able to retrieve the total count.
https://api.facebook.com/method/fql.query?query=SELECT%20url,%20share_count,%20like_count,%20comment_count,%20total_count,%20click_count%20FROM%20link_stat%20where%20url=%27http://www.google.com%27
<fql_query_response list="true"><link_stat>
<url>http://www.google.com</url>
<share_count>5860640</share_count>
<like_count>1446662</like_count>
<comment_count>1775201</comment_count>
<total_count>9082503</total_count>
<click_count>265614</click_count>
</link_stat></fql_query_response>
http://graph.facebook.com/?id=http://www.google.com
{
"id": "http://www.google.com",
"shares": 9082503
}
The more up to date way of using your FQL would be
https://graph.facebook.com/fql?q=SELECT%20url,%20share_count,%20like_count,%20comment_count,%20total_count,%20click_count%20FROM%20link_stat%20where%20url=%27http://www.google.com%27
If you'd like to use the old (deprecated, but still working) api.facebook.com endpoint, try
https://api.facebook.com/method/links.getStats?urls=http://www.google.com&format=json
This doesn't employ FQL at all, but you can't be sure how long this works. It's not even in their docs anymore. FQL will be around 2 years from the moment Facebook announces the successor of the Graph API v2.0, so I would recommend go go along with the first suggestion.
Graph API v2.0 doesn't have an endpoint IMHO to generate URL sharing stats other than the FQL method.

Facebook API For Pulling Reviews

Has anyone seen a full example of how to pull facebook reviews using the graph api.
According to the docs:
A page access token is required to retrieve this data.
I have code that asks a user to login already and gets an auth token which I can use to post a message to their facebook feed. Is there an additional step I need to do to be able to read their reviews/ratings?
Here is an example of the code to post to their feed/page.
response = Curl.post("https://graph.facebook.com/#{page_id}/feed", {
:message => message,
:access_token => auth_token
})
Thanks
If you're referring to Page Ratings (different from App Reviews!), then the endpoint is
GET /{page_id}/ratings
as described here: https://developers.facebook.com/docs/graph-api/reference/page/ratings You'll need a Page Access Token for this.
Where I get a little bit confused is that you mention that you want to
read their reviews/ratings
In that case it's something else, because afaik it's currently not possible to query the User's Page ratings via Graph API or FQL. It's was only possible to query App Reviews via FQL (see https://developers.facebook.com/docs/reference/fql/review/) (Update: FQL is no longer available since 2016)
You need to set permission in the app to access the {GET /{page_id}/ratings} API. The permission is common for
/page/comments,
/page/posts,
/page/ratings,
/page/tagged,
and the permission name is "pages_read_user_content"
https://developers.facebook.com/docs/permissions/reference/pages_read_user_content

feed_PublishTemplatizedAction() returns true, but not posted on my FansPage

I need to publish a feed entry to my FansPage. For that I have used the codes as follows,
userClient = new FacebookXmlRestClient(api_key, secret);
if(userClient.users_hasAppPermission(Permission.OFFLINE_ACCESS, longFacebookUserID)){
TemplatizedAction action = new TemplatizedAction("{actor} recommends {book}");
action.setPageActorId(ctProfileId);//fansPageId
action.addTitleParam("book", "<a href='http://www.amazon.com/Hamlet/dp/0140714545/'>Hamlet</a>");
action.setBodyTemplate("{actor} is using BooksApp!");
action.setBodyGeneral("100 other people recommend this book!");
action.addPicture("http://code.google.com/hosting/images/code_sm.png", "http://www.google.com");
userClient.feed_PublishTemplatizedAction(action);}
When Im executing this code, feed_PublishTemplatizedAction() returns true but not posted on my FansPage.
Can anybody give me the Guidelines.
Thanks,
jerry.
Feed templates have been deprecated and no longer work. You should read up on Feeds / Stream publishing. In addition, you should mode away from the REST API and use the Graph API instead. You app and code appear massively out of date.
You can use the '/me/feed' API call to publish to the users wall.

using facebook graph API vs FQL insights

I'm trying to get insights from facebook for some pages I have admin rights to. I'm able to get the correct data with the graph API but when I try with FQL I get an empty JSON object. Any idea what the problem may be?
I think the query is correct because I do not get any 400/500 errors. I also think the permissions are correct because I'm using the same framwork with the graph API solution and it works fine. Maybe you need additional permissions to use FQL? I have manage_pages and read_insights.
I'm implementing with basic text replacement on the template URIs from facebook's documentation.
EDIT: I think the problem may be that I don't actually have the read_insights permission. I do have the manage_pages permission. Perhaps this explains why I can access insights through Graph API but not FQL?
Graph API query:
string insight_str = "https://graph.facebook.com/APP_ID/insights/FIELD/FREQ?access_token=ACCESS_TOKEN";
string url = insight_str.Replace("FIELD", "page_impressions").Replace("FREQ","day").Replace("APP_ID", accounts[i].id).Replace("ACCESS_TOKEN", accounts[i].access_token);
https://graph.facebook.com/xxxxxxxx/insights/page_impressions/day?access_token=xxxxxxxx
Graph API parsed JSON result:
page_impressions
2011-12-28 412
2011-12-29 971
2011-12-30 373
FQL query:
string query_str = "https://graph.facebook.com/fql?q=QUERY&access_token=ACCESS_TOKEN";
string query = "SELECT+metric,value+FROM+insights+WHERE+object_id=APP_ID+AND+metric='FIELD'+AND+end_time=1322722800+AND+period=86400";
string url = query_str.Replace("QUERY",query).Replace("FIELD","page_impressions").Replace("APP_ID",accounts[i].id).Replace("ACCESS_TOKEN",accounts[i].access_token);
https://graph.facebook.com/fql?q=SELECT+metric,value+FROM+insights+WHERE+object_id=xxxxxxxx+AND+metric='page_impressions'+AND+end_time=1322722800+AND+period=86400&access_token=xxxxxxxx
FQL JSON result:
{"data":[]}
I have the same problem with Facebook C# SDK version 5.4.1 and 5.3.2 (see my post Error with FQL query with library 5.4.1)
I always receive an empty response like you.
You must have the read_insights permission.
I think the end time in your example is slightly off. It needs to fall exactly at midnight PST. I obtained a value once I moved the time forward an hour, to 1322726400.

Is there a way to insert an #mention into a Facebook status update posted with pyfacebook?

I have some code like the following in my application:
message = "Hi, #John Doe!"
postID = fb.stream.publish(
message = loader.render_to_string('wall_post.phtml', {'message':message}),
action_links = simplejson.dumps([{'text': "Check out blah", 'href': "http://blah.dev"}]),
target_id = 'nf'
)
Is there any way to represent a facebook #mention in the message string so that facebook converts it to a profile link for the mentioned user?
I've also been looking for an answer to this. The facebook website uses the format:
#[139730900025:PhotoGrabber] is awesome
to represent the links but I haven't been able to make that work. I re-posted a thread on the facebook forum under the "Stream" category since your post wasn't getting any attention:
http://forum.developers.facebook.com/viewtopic.php?id=47885
Mention it's partially available by open graph now. You can use only when posting an open graph ACTION
Check:
https://developers.facebook.com/docs/opengraph/mention_tagging/
It seems still impossible to use #mention tagging in classic feed posting via API
I'm pretty sure this is impossible at the moment. If it were posible by using the format that tam7t suggested it should work... Your best bet is asking them to add that to their api stream parser.
This is not possible at the moment, sorry.
AFAIK facebook's API does not allow this. The only approach that I know of at the moment would be to write a screen scraper to do these posts using the format described by tam7t's answer. If you use the mobile version of facebook's site (m.facebook.com) it makes it much easier.
NOTE: This might be a violation of Facebook's Application TOS.
Edit:
Here is some ruby code that will do the trick, using the Mechanize Gem
require 'mechanize'
agent = Mechanize.new
agent.user_agent_alias = 'Mac Safari'
page = agent.get('http://m.facebook.com')
form = page.forms.first
# enter credentials
form.pass = 'user password'
form.email = 'user#example.com'
page = agent.submit form
# go straight to page to post on
page = agent.get("http://m.facebook.com/wall.php?id=PAGE_ID_NUM")
form = page.forms.first
form.message = "#[139730900025:PhotoGrabber] is awesome"
page = agent.submit form
NOTE: Obviously (as tiagoboldt kindly pointed out) it would be wrong to store / utilise the credentials of other people in your application. This approach would only be appropriate for making posts from a facebook account that you controlled.
That said, back to the original question of putting an #mention in a wall post, I have noticed that whilst the post and #mention go up on the wall fine, this method does not propagate the post to the mentioned user/page's wall. Not sure if that is important to you.