fql get valid photo - facebook-fql

I have written a fql to get photo from facebook.
fql = 'SELECT caption, owner, pid, src_big, created
FROM photo
WHERE aid IN (SELECT aid
FROM album
WHERE owner IN (111111) )
LIMIT 1,10';
But I found sometimes the app cannot get the photo from the src_big column.
How to write a fql or any other methods to make sure the returned photo url (e.g.src_big) is accessible?

Taken from the Facebook API:
The URL to the full-sized version of
the photo being queried. The image can
have a maximum width or height of
720px. This URL may be blank.
I think your issue is that you don't always get a src_big image. You should also query for the src_small image, as a fallback. Also, you can add a default image of your own, so that if neither image is available or acceptable, you can just use your default image.
For example:
fql = 'SELECT caption, owner, pid, src_big, src_small, created
FROM photo
WHERE aid IN (SELECT aid
FROM album
WHERE owner IN (111111) )
LIMIT 1,10';
And then in your code, check for something like....
//Where results = photo results array...
for(var i = 0; i<results.length; i++){
if(results[i].src_big == null){
if(results[i].src_small == null){
//Use default image
}
else{
//Use src_small
}
}
else{
//use src_big
}
}

Related

FQL for getting facebook user ids does not return "paging" key in response

Hi i want to get list of my fabebook friend ids with paging of 100 users.
The problem is that if i set hte FQL to
NSString *fqlString = #"SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) LIMIT 300";
It returns me as expected the only first 300 users in the table with out any reference to next page.
Result: {
data = (
{
uid = 1519xxx;
},
{
uid = 9806xxx;
}
....
);
}
if i request friends with [FBRequest requestForMyFriends] it returns me all of my friends and additionaly a paging key with the url object for next page.
The question is how can i tell with FQL to give me lists of 100 users with paging to next 100 users.
The Graph API returns paging links; FQL does not. So you’d have to do that yourself, by making another query including an OFFSET parameter.

Why facebook album id is zero in FQL?

I am using FQL. I am using the following set of query to get info about album,
SELECT aid,src_small from photo where pid='100000244468314_1600187'
i get the following result,
{
"data": [
{
"aid": "0",
"src_small": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash3/545289_450190444999100_1364645489_t.jpg"
}
]
}
Then i gave the following query to get the album name and owner,
SELECT aid, owner, name, object_id FROM album WHERE aid="0"
But i get the following,
{
"data": [
]
}
Why is album id 0? and why it returns None? Please help. I am new to FQL
Try this query instead:
SELECT aid, owner, name, object_id FROM album
WHERE object_id IN
(SELECT album_object_id FROM photo where pid='100000244468314_1600187')
It looks like aid and pid fields are on their way to be deprecated in exchange for the object_id fields.

How do I know the current user liked corresponding link?

I make a page tab application. The application displays some items, each of which has a like button. Like buttons attached to the corresponding url item. I need to display to users who liked, some text in those elements that have collected 10+ likes.
So, I write this code:
// Get a link statistics
$link_stat = $fb->api(
array(
'method' => 'fql.query',
'query' => 'SELECT like_count FROM link_stat WHERE url="http://myurl.com/item1.html"'
)
);
if ((int)$link_stat[0]['like_count'] > 10)
{
//Get like by current user_id and link object_id
$like = $fb->api(
array(
'method' => 'fql.query',
'query' => 'SELECT user_id, object_id FROM like WHERE user_id=me() AND object_id IN (SELECT id FROM object_url WHERE url="http://myurl.com/item1.html")'
)
);
var_dump($like);
}
I run this code upon request permission *user_likes* and *read_stream*, but it outputs array(0) { }.
A question is, how do I know the current user liked corresponding link?
Oh, sh… I didn't notice that there is a table url_like (or recently emerged?).
I made this FQL query, and it returned the required response:
SELECT user_id FROM url_like WHERE user_id = me() AND url = "http://myurl.com/item1.html"
Cpilko, thank you very much! =)
You could try rewriting your query to go at it the other way. See if your url exists in a user's likes.
This works for me:
SELECT url, id, type, site FROM object_url WHERE id IN (SELECT object_id FROM like
WHERE user_id=me()) AND strpos(url, "myurl.com/item1") >= 0

Fetch friends data with Graph API

I need fetch user's friends data with next fields: id, name,
gender, birthday, city, country, profileUrl, pic, pic_small,
pic_big, is_app_user.
Before I used FB.Data.query, but now it's deprecated.
FB.Data.query('select uid, first_name, last_name, name, pic,
pic_small, pic_big, birthday_date, sex, current_location,
profile_url, is_app_user from user where uid in (select uid2 from
friend where uid1 = {0}', uid).
How to fetch friends, who are using app?
I can get all fields what i need, but for example for pictures i need to do additional requests. Can i get all needed fields in single request?
You can still use same FQL query with Graph API and JavaScript SDK
var query = 'SELECT uid, first_name, last_name, name, pic, pic_small, pic_big, birthday_date, sex, current_location, profile_url, is_app_user FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = ' + uid;
FB.api('/fql',{q:query}, function(response){
console.log(response.data);
});
You for sure can also get almost same data with Graph API not using FQL at all:
FB.api('/'+uid+'/friends', {
fields: 'id,first_name,last_name,name,birthday,gender,location,link,installed'
}, function(response){
console.log(response.data);
});
You have a bit different names and other format (ex location) for those details and miss the picture details in results but this is simple, user picture is available on URL in form http://graph.facebook.com/USER_ID/picture
use ?type=square | small | normal | large to request a different photo
I've been poking around with this too, using PHP. This is what I came up with:
$user_friends = $facebook->api('/me/friends?fields=installed');
$user_players = array();
foreach ($user_friends['data'] as $userfriend)
{
if (array_key_exists('installed', $userfriend))
{
array_push($user_players, $userfriend);
}
}
The Following Helps you to fetch user's friend details using graph api
NSString friendId =10020020 //Store Friend ID;
NSString * pRequestString = [NSString stringWithFormat:#"%#?fields=name,picture,work,hometown,birthday,devices,interests",friendId];
[[FBRequest requestForGraphPath:pRequestString ] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"%#",result);
}];

Error getting photos from a Facebook album using FQL and Javascript SDK

I use this function to get photos from a facebook album. Please give advice why it returns blank space.
function getPhotos(aid) {
sql = 'SELECT pid, src_big, src_small FROM photo WHERE aid='+aid+' ORDER BY modified desc';
FB.api(
{
method: 'fql.query',
query: sql
},
function(response) {
console.log(response);
}
);
}
While posting the error would help, you should wrap the aid in quotes since it's a string field (ref):
sql = 'SELECT pid, src_big, src_small FROM photo WHERE aid="'+aid+'" ORDER BY modified desc';
Also make sure you have the right permission user_photos.