PHP Facebook FQL for query a public Note - php

I have created an app with no special permissions. With this app I query Facebook events to display on my website. That all works fine.
I now wanted to expand the website with displaying Facebook Notes of my Fan Page. When I try to Implement that, I get the error message:
"Requires user session"
On the FQL-Note API reference they say "any valid access_token if it is public note written by a page." I think I have a valid public token.
require '../src/fb-sdk/src/facebook.php';
$facebooknotes = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxx',
'secret' => 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',
'cookie' => false, // enable optional cookie support
));
$fql_notes = "SELECT uid, note_id, title, content, content_html, created_time, updated_time FROM note WHERE uid = 149018831796518";
$param = array(
'method' => 'fql.query',
'query' => $fql_notes,
'callback' => ''
);
$fql_notesResult = $facebooknotes->api($param);
foreach($fql_notesResult as $keys => $fbnotevalues){ echo "<h2>" . $fbnotevalues['title'] . "</h2>" . $fbnotevalues['content_html']; }
Can someone help?
Regards,
rimshot

FQL does not seem to be able to get a page's notes. The uid field is looking for a user id. My guess is if you got the appropriate access token, you would still end up with an error because your ID does not belong to a page.
To get at the notes of a page, you need to use the graph API:
$fql_notesResult = $facebooknotes->api('/149018831796518/notes', 'GET');
foreach($fql_notesResult as $keys => $fbnotevalues){
echo "<h2>" . $fbnotevalues['subject'] . "</h2>" . $fbnotevalues['message'];
}

Related

facebook api return nothing but with me I have the data

I make a Facebook app, now we change it from server and I run again the codes to test it, and I found that it works perfectly except for one FQL. I get the user info with ->(/me)
The FLQ works (I tested with Facebook tools). My connection and scope its correct. any idea?
I leave you my fql
$scope = 'email,read_stream';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
// Get the current user
$user = $facebook->getUser();
$fql = "SELECT type, source_id, share_count, likes, permalink, description, post_id, message, target_id, created_time, attachment
FROM stream
WHERE source_id = me() and type in (46, 80)
order by created_time desc
LIMIT 500";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
print_r($fqlResult);
I wouldn't use FQL personally as there's a reason they depreciate the old API's, but to access feed data of the user you need to have granted access from the API for your application, it should handle access_tokens automatically but when your user logs in with your website you want to be using
$params = array(
'scope' => 'read_stream, friends_likes',
// Access to feed data (read_stream) and whatever else you need
'redirect_uri' => 'https://www.myapp.com/post_login_page'
);
$loginUrl = $facebook->getLoginUrl($params);
Then you can access all the information you want with the api query:
$facebook->api('/me?fields=feed.fields(source,id,shares,likes,link,description,message,created_time)', 'GET');
I highly recommend using the Facebook Graph API Explorer to test API queries and retrieve all the information you need
Hope that helps mate!
In the parameter array, add one more parameter : access_token and give it the valid access token value
I found my problem,
the code works, but I was asking for two specific types.
and type in (46, 80)
When I remove it it appear all the stream :)
Thanks to everyone

How to get details of all users using a particular application using PHP SDK?

I created an application in facebook. How to get details of all users of this application even
if they are not my facebook friends. I need a PHP SDK query
Can someone help me please?
You can use FQL with PHP sdk :
http://developers.facebook.com/docs/reference/php/facebook-api/
Below is the query which should get you the desired results.
$config = array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
);
$facebook = new Facebook($config);
$facebook->api(array('method' => 'fql.query', 'query' => "SELECT uid FROM user WHERE is_app_user = '1'"));
For users table you can look at : http://developers.facebook.com/docs/reference/fql/user/
Though it is not tested but i can hope it will point you in right direction.

PHP Facebook API - extended permission data not showing up with (offline) access_token

I'm trying to retrieve profile information regarding users who allowed my app to collect data about them (birthday, location etc.). This works fine when, and only when, the user actually visits my app and authenticates with facebook through token exchange.
However, I want to be able to routinely check if the user location hasn't changed, also if a user adds information about himself on FB, I want to "sync" it with my app, so that the information stays the same.
So I save the users access token, and later on, with a cron job I use the token to get his profile:
$user = mysql_query ... <- get data from mysql
and then:
$user_profile = $facebook->api('/'.$user['uid']);
And it works, of course, but all the data I want from using extended permissions - just doesn't show up!
Is the the curse of the offline_access disabling? Or do I need to use a different way of obtaining such data. I tried adding ?fields=birthday and etc. on the end of the query, but it still doesn't work.
Not sure if this is what you meant by 'offline_access disabling' however Facebook are deprecating offline_access as you can see in the roadmap:
http://developers.facebook.com/roadmap/
You can read more information on the deprecation here:
http://developers.facebook.com/roadmap/offline-access-removal/
Also, are you correctly setting the access token received from the database?
$facebook->setAccessToken($user['access_token']);
Found out how to accomplish this - the access token has to be passed as an additional parameter on the api queries, like such:
$user_profile = $facebook->api('/'.$user['uid'].'', array('access_token' => $session['access_token']));
In case anyone wonders onto this page, here is a way to use saved access tokens, to access full information about the user you want, without having to authenticate:
<?
require "facebook.php";
$facebook = new Facebook(array(
'appId' => your_app_id,
'secret' => your_app_secret
));
// get the saved user details
$user = mysql_fetch_assoc(mysql_query('SELECT * FROM `facebook_tokens` WHERE `id` = "1"'));
$session = array(
'access_token' => $user['access_token'],
'secret' => $user['secret'],
'session_key' => $user['session_key'],
'uid' => $user['uid']
);
$sig = '';
foreach($session as $key => $value) {
$sig .= implode('=', array($key, $value));
}
$session['sig'] = md5($sessionStr.'Your App Secret');
$facebook->setSession($session, false);
$user_profile = $facebook->api('/'.$session['uid'], array('access_token' => $session['access_token']));
echo '<pre>';
print_r($user_profile);
echo '</pre>';
?>

Need help posting to my own wall in Facebook with PHP

The code below is not working for some reason:
require './facebook.php';
$facebook = new Facebook(array(
'appId' => 'working_app_id',
'secret' => 'working_secret'
));
// Get User ID
$user = $facebook->getUser();
$token = $facebook->getAccessToken();
print $token; // token shows.
$attachment = array
(
'access_token'=>$token,
'message' => 'This is where the message will go.',
'name' => 'Name Text',
'link' => 'http://www.website.com',
'description' => 'Description text.'
);
$result = $facebook->api('/me/feed/','post',$attachment);
exit;
I am getting the following error:
Uncaught OAuthException: An active access token must be used to query information about the current user.
When I print the token, it appears to be a real token. I just have no idea what I could be doing wrong. All I want to do is post a very simple status update to my own page.
I don't know why I can't seem to figure this out. I'm banging my head against the wall on this one because it should just be so simple to post a quick little status update to my wall in Facebook from PHP.
Note: The App Type I created to get my appID and secret was a "Website".
Check out this answer, it appears that you are using the wrong method to get your access token.
Howto use FB Graph to post a message on a feed (wall)

tagging a page in photos

Greetings
Here's what's up:
I'm working on an app where the user or a page they administrate is tagged in their own image, however, tagging a page they administrate doesn't function, I have no trouble with the user being tagged.
Here's some code:
$tdata = array('tag_uid' => $fb_id,'x' => 0,'y' => 0);
$datatags[] = $tdata;
$attachment = array(
'access_token' => $access_token,
'tags' => $datatags
);
$attachment['image'] = '#'.realpath($image_name.);
$result = $facebook->api('/'.$album_id.'/photos', 'POST', $attachment);
$fb_id is either the ID for the user or the page. which is grabbed using /me/accounts in the Graph API
Thanks!
Per the documentation you cannot do this:
You can specify which user to tag using two methods: in the URL path
as PHOTO_ID/tags/USER_ID, or in a URL parameter as
PHOTO_ID/tags?to=USER_ID. Currently, you cannot tag a Page in a photo
using this API.
https://developers.facebook.com/docs/reference/api/photo/

Categories