Why is this FQL call failing? - facebook

When I do a FQL query like the following (where <userId> is the Facebook ID of my FB friend):
SELECT type, post_id, created_time, updated_time, source_id, message, description, attachment FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid = <userId> AND type = 'newsfeed') AND is_hidden = 0 LIMIT 250
I'm getting the following error:
"error": {
"message": "(#606) uid in the where clause must be the session user",
"type": "OAuthException",
"code": 606
}
This seems wrong to me, because the examples in the stream_filter docs clearly use this example.
If the only way to get a stream_filter is by calling WHERE uid=me() then what is the point of the WHERE clause at all?
Is this a permissions issue with my access token?

If you are doing an FQL query based on the uid of your friend, you need to be authorized. Once authorized, you can add the access token granted by the user (in this case, your friend) to your query and have permission to get the results you're querying for.
This is because you're trying to fetch data, which in this case being their news feed comprised of posts created by their friends and pages they follow, that belongs to the user, which essentially belongs to them. You need to authorized to be able to access their data or act on their behalf to post photos and such.
However, if you're trying to get their own stream of posts that they themselves generate, you can totally get those, assuming that they are public and accessible by their set permissions. You can use a Graph API call:
https://graph.facebook.com/<userId>/feed?access_token=<your access token>
I'll also throw this in: You can read your own news feed as well with a Graph API call:
https://graph.facebook.com/me/home?access_token=<your access token>
You just need to make sure you have the 'read_stream' permission. If you try to get the news feed of another user by replacing 'me' with the user id, you'll get an error from Facebook:
{
"error": {
"message": "You can only access the \"home\" connection for the current user.",
"type": "GraphMethodException",
"code": 100
}
}
This further confirms that you can't access another user's news feed unless you have their permission, ie. being granted an access token that belongs to them.

Related

Querying stream table with multiple source id throws exception

I am using FQL query to get update for list of source ids.
select type,post_id, message,permalink, created_time,updated_time,type,message_tags, app_data, attachment from stream where source_id IN (page_id1,page_id2)
I have used my app access token, also I have added read_stream permission in extended permissions.
I got following error.
{
"error": {
"message": "(#606) Queries for multiple source_ids require a non-zero viewer that has granted read_stream permission",
"type": "OAuthException",
"code": 606
}
}
My app has 10 users.I have check insights of my app,it show Monthly Active Users :10.
Am I missing anything.

Getting Public Info about Location in Facebook Graph API

I need to get the living city of each person in a group. Including people that are not my friends.
In the browser seeing facebook profile of some unknown person, they show "lives in ...", if this is set as public information. They include the link to the city object with the city id in the link. That's all that I need.
But, using a facebook app that I created to use the facebook graph api, this information is not public. I can only get the user propriety 'location' from friends of my that I have permission to see it. I gave ALL the possible permissions to my app.
In the api explorer, when I use it as REST, they show few informations about someone not friend of mine.
https://developers.facebook.com/tools/explorer/
Also in the api explorer, when I use the FQL, it didn't works.
This query works, returning the JSON with the data:
SELECT uid, name FROM user WHERE username='...';
But this other query doesn't work:
SELECT uid, name, location FROM user WHERE username='...';
They return a json with a error code:
{
"error": {
"message": "(#602) location is not a member of the user table.",
"type": "OAuthException",
"code": 602
}
}
I asked for ALL the permissions options in the token. And I can get this info in the browser version of the facebook. But how can I get it with the API ?
The location field only exists in the Graph API table. Since you are using FQL, here are the location fields available to you:
current_address: the current address of the user,
current_location: the user's current location,
hometown_location: the user's hometown (and state).
Permissions:
user_location or friends_location permissions to view: current_location,
user_hometown or friends_hometown permissions to view: hometown_location.
Source: https://developers.facebook.com/docs/reference/fql/user/

Facebook post impressions are null in FQL stream query

According to the FQL Stream documentation the following query is supposed to return impression counts when run by an authenticated page owner, yet it never does. We have the page owner authenticating directly in the graph api explorer with extended permissions (read_stream, read_insights), but the impression counts are always null.
Is anyone able to get this working?
SELECT post_id, actor_id, message, impressions FROM stream WHERE actor_id = {owned_page} and source_id = {owned_page}
I think its missing in the documentation, but you should make this call using the page access token instead of user access token to get it worked.
So here are the steps:
Get the following permissions from the user and get the user access_token:
manage_pages - to get the page access token
read_insights - to read the impressions (as mentioned in the doc)
read_stream - for all posts that the current session user is able to view
Using that token, get the page access_token with the call-
/{page-id}?fields=access_token
(optional) Check out my answer here to extend this page access token that will never expire. (Basically to avoid some steps)
Using the page access token, run your query-
SELECT post_id, actor_id, message, impressions FROM stream WHERE actor_id = {owned_page} and source_id = {owned_page}
This will fetch you the impressions(if any) in the result.
Hope that helps.!

HTTP 400 Error when accessing Friends list in Facebook Graph API

When I access the list of my friends using the URL https://graph.facebook.com/me/friends?access_token=... I can see the list of my friends. I can do this programmatically as well.
Now, when I take the ID of any of my friends and replace it with "me" in the above URL, and paste the URL in the browser, I can see my friend's friends. I am unable to do this programmatically because it is giving me an HTTP 400 ERROR.
Does anyone know why this is possible by pasting the URL and not programmatically?
You can not get the "friends of friends" using the facebook api.
For example, try the simple /me/friends with the Graph API Explorer, it should work fine.
Then, take one of the ids there and try the same with FRIEND_ID/friends and you should get this:
{
"error": {
"message": "(#604) Can't lookup all friends of FRIEN_ID. Can only lookup for the logged in user or the logged in user's friends that are users of your app.",
"type": "OAuthException",
"code": 604
}
}
The error itself is very straight forward and explains exactly what the problem is.
As for why that translates into a 400 error code for you is unclear.
Edit
You can't see the "friends of friends" in the browser as well, the reason that it works for you (probably) is that the user(s) you check the friends for (USER_ID/friends) installed the app that the access token belongs to, from the way you got to that url I assume that the app is the "Test_console".
How to check? Copy the access token from the url (USER_ID/friends?access_token=xxxxx), go to the Facebook Debugger and paste the token in the text field and click "Debug", it will show you info regarding the application.
The user you checked it for probably has that app "installed", if you check it for other users you will get that error when you get to a user who does not have that app "installed".
I hope this clarifies it for you.
I got friends of friends(limited) who are using application. I had same problem. Though it is very late for answering question, it will help somebody. That's why answering this question.
We can get friends of friends those are app users.
$fb_id= user id whose friends of friends required.
Try this fql query.
$query="SELECT uid, name, work_history FROM user WHERE uid IN (SELECT
uid2 FROM friend WHERE uid1 IN (SELECT uid FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = $fb_id ) and is_app_user=1) )";
It needs following requirements:
Your friend needs to be using application.
Permission from application read_stream, publish_stream, publish_checkins.

Get Facebook fanpage status using Facebook app access token

Is it possible to retrieve Facebook page statuses using an app access token?
According to the documentation I could use "any valid access_token or user access_token" but when I try to use the application access token I'm getting the following message: "A user access token is required to request this resource.". Am I generating the app access token in a wrong way? Is there anyway to access the statuses of a public Facebook fan page without a user?
It seems that a user access_token is required to query this connection.
Tried without any access_token in the Graph API Explorer on redbull page and the result was:
{
"error": {
"message": "An access token is required to request this resource.",
"type": "OAuthException"
}
}
But after providing an app access_token:
{
"error": {
"message": "A user access token is required to request this resource.",
"type": "OAuthException"
}
}
This is a bit misleading!
Don't know if your still facing this issue. But here's a workaround :
By asking the graph API, you have this issue, but by using the FQL langage, it works perfectly with an App ID!
Here's an example for the 'PSG' page :
https://api.facebook.com/method/fql.query?query=SELECT post_id, type, attachment, message FROM stream WHERE source_id IN(SELECT page_id from page where username='PSG')&access_token=YOUR_APP_ACCESS_TOKEN
;)