I am trying to gather the last posts on my fan page to update on my website using the php SDK, I have the following code but it returns an empty array, is there something I am missing? It doesn't seem obvious to me how this won't work, I have tried for literally days now and still get no further following other tutorials etc..
require_once("fcbk/facebook.php");
$config = array();
$config['appId'] = '********';
$config['secret'] = '*********';
$facebook = new Facebook($config);
$pageid = "*********";
$pagefeed = $facebook->api("/" . $pageid . "/feed");
var_dump($pagefeed);
Thanks for all your help.
I've had the same issue, people seem to have solved it here :
Solutions is basically use FQL to filter last entries, get each post_id and retrieve each post usind another call passing all these IDs
check this post here :
Facebook FQL. Which is the easiest way to get all page changes in one single query ordered by date/time?
it worked for me.
Related
I'm trying to get keyword ideas from AdWords API by page URL, but so far I'm only able to get keywords list by another keyword.
What I want to do is possible via web interface, but as for API, docs say that the only available value for ideaType property is KEYWORD.
Are there any alternatives for ideaType, maybe via creating a new campaign, or something else?
I'm using PHP.
I'm new to Google AdWords. Help appreciated!
In fact, I misunderstood the goal of ideaType property. This property is not the input search parameters type.
For getting keyword ideas by URL you can use RelatedToUrlSearchParameter class.
In my case code looks like following (the most relevant part):
$selector = new TargetingIdeaSelector();
$selector->requestType = 'IDEAS';
$selector->ideaType = 'KEYWORD';
$selector->requestedAttributeTypes = array('KEYWORD_TEXT', 'SEARCH_VOLUME', 'CATEGORY_PRODUCTS_AND_SERVICES');
$relatedToUrlSearchParameter = new RelatedToUrlSearchParameter();
$url = $_GET['url'];
$relatedToUrlSearchParameter->urls = array($url);
$selector->searchParameters[] = $relatedToUrlSearchParameter;
I am trying to pull a public page from facebook using php and json to sort the data received. I have everything working perfectly apart from replies on comments on posts. I can get all the list of comments on a post but the replies to that comment do not appear on the json data that is returned to me. I believe when the user of the page comments on his own post the story tag is given to the comment and it is unrelated to the comments section of that post. But if anybody else replies to a comment i cannot see their message anywhere. Is there any way to try and get the replies of comments returned in json along with everything else?
edit: found a better solution
see the answer here: How to get the image from a facebook photo comment?
the query you want to perform is
/{page-post-id}/comments?fields=from,message,id,attachment,created_time,comments.fields(from,message,id,attachment,created_time)
to query this via PHP you would do something like this:
$page_comment_id = 12345; // put your id here
$access_token = ''; // put your facebook access token here
$url = 'https://graph.facebook.com/' . $page_comment_id . '/comments?fields=from,message,id,attachment,created_time,comments.fields(from,message,id,attachment,created_time)&access_token=' . $access_token;
$data = json_decode(file_get_contents($url),true);
print_r($data);
I'm curious to use the facebook graph API as I don't like the simple like button with number of likes next to it. However I'm finding their documentation a bit confusing. I want to do this via PHP so I'm assuming I need the PHP SDK, is that right?
I'm looking at this page Graph API: Page however I don't understand how I would call the likes.
I'm not asking for someone to code this for me, just a little help in the right direction to understand how it works :)
Try this:
$json = #file_get_contents("http://graph.facebook.com/yourpage");
$json1 = json_decode($json,true);
$likes = $json1['likes'];
echo $likes;
This is pretty straightforward. Using the ID or the username of the page, access that
node via the Graph API:
PAGE_ID?fields=likes
In PHP would be something like:
$token_string = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id='.$appID.'&client_secret='.$app_secret.'&grant_type=client_credentials');
$likes_response = file_get_contents('https://graph.facebook.com/PAGE_ID?fields=likes&'.$token_string);
$likes_obj = json_decode($likes_response);
$likes = $likes_obj->likes;
echo 'Likes count for page: ' . $likes;
I've been running a photography site for just over two years and displayed stats about how many facebook likes and shares each image page has accumulated underneath each image.
The code I have used to get this info and put it into the variables is this:
<?php // Get Facebook Stats for Shares Likes Comments etc...
$url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($this->canonicalurl);
$xml = file_get_contents($url);
$xml = simplexml_load_string($xml);
$shares = number_format($xml->link_stat->share_count);
$likes = number_format($xml->link_stat->like_count);
$comments = number_format($xml->link_stat->comment_count);
$total = number_format($xml->link_stat->total_count);
?>
All was fine until today I switched from PHP5.2 to 5.4 and suddenly all the stats no longer appear. I've read around a little bit and some people were saying that I need to set allow_url_fopen = 1 but that was already set.
Someone else was saying that it may have something to do with using file_get_contents, but I got no concrete result.
Can anyone please shed some light on what might be wrong? Is there another way to write the above without using file_get_contents that would get around this issue if that is to blame?
Thanks!
The error here is that the number_format needs to be a double, but $xml is an object. You can just remove number_format, but I recommend intval for it.
<?php // Get Facebook Stats for Shares Likes Comments etc...
$url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($this->canonicalurl);
$xml = file_get_contents($url);
$xml = simplexml_load_string($xml);
$shares = intval($xml->link_stat->share_count);
$likes = intval($xml->link_stat->like_count);
$comments = intval($xml->link_stat->comment_count);
$total = intval($xml->link_stat->total_count);
?>
Im using the SDK 3 by facebook, and to store the facebook id i am doing this:
$facebook_id = $user;
Which works a treat! However... i cannot access individual items in the array, like i remember with the previous SDK you could do:
$first_name = $me['first_name'];
However, i have tried that, and $user['first_name'] and stuff but getting no where! I cant find any documentation of this either on their dev website or on the internet :/
Many thanks.
Ian.
Seems like $user is just the Facebook User ID that you get through the authentication flow. If you want to get user info, you need to make a separate Graph call, like so:
$res = $facebook->api('/me');
$first_name = $res['first_name'];