I used following code to access facebook page posts.
$accessToken = 'EAAlGssgdgQIBAHuD9ZBZB6RWZClM3bmm8Vjv2nZBNmotTTnubgzdK4aiHbqJwhRlELjAurPEHKSqxJS7c0Pyd5ZBuqZAo2keabbkubx0AZCl3m6brDGlkXNgMq9dtNUZAx4P6QwdsXwNvJaEi2j3YDsHpZABiRxRK6qMAmZAyynLvJNCJ41ZBn9se28QUsDHG72mhZCzHFLpLQUxZCAZDZD';
$id = '109395947376896';
$url = "https://graph.facebook.com/$id/posts?access_token=$accessToken";
$result = file_get_contents($url);
$decoded = json_decode($result, true);
var_dump($decoded);
and get the following result. screenshot is attached
how do I get images of posts??
Without specifying the fields, you will only get default ones. This is how you can get fields (checkout the API docs for Posts about available ones):
$url = "https://graph.facebook.com/$id/posts?access_token=$accessToken&fields=full_picture,message,...";
Source: https://developers.facebook.com/docs/graph-api/reference/post/#fields
You can get them in field parameters
picture
full_picture
child_attachments
Also refer https://developers.facebook.com/docs/graph-api/reference/post/
Related
Im new to php and tried to get a json object from the twitch API to retrieve one of its values and output it. i.e
i need to get the information from this link: https://api.twitch.tv/kraken/users/USERNAME/follows/channels/CHANNELSNAME
plus i need to to something so i can modify the urls USERNAME and CHANNELSUSERNAME. I want it to be a api to call for howlong user XY is following channelXY and this will be called using nightbots $customapi function.
the date i need from the json is "created_at"
Since we were able to clear out the errorsheres the final PHP file that works if anyone encounters similiar errors:
<?php
$url = "https://api.twitch.tv/kraken/users/" . $_GET['username'] . "/follows/channels/" . $_GET['channel'];
$result = file_get_contents($url);
$result = json_decode($result, true);
echo $result["created_at"];
?>
You have a typo in your code on the first line and you're not storing the result of your json_decode anywhere.
<?php
$url = "https://api.twitch.tv/kraken/users/" . $_GET['username'] . "/follows/channels/" . $_GET['channel'];
$result = file_get_contents($url);
$result = json_decode($result, true);
echo $result["created_at"];
You have to call the page this way page.php?username=yeroise&channel=ceratia in order to output the created_at value for this user and this channel.
In your code you're using 2 different ways to get the content of the page and you only need one (either file_get_contents or using CURL), I chose file_get_contents here as the other method adds complexity for no reason in this case.
I have Page Id "252079588308065" in facebook. I just want to get the number of likes of this page using graph API or FQL.
Is it possible to get number of likes count of a particular page.
Please provide me a solution
Here is a way of getting the like count using Graph API.
<?php
//The following code returns the Number of likes for any facebook page.
//Page Id of TechRecite.com. Replace it with your page.
$page_id = "138564926335348";
$likes = 0; //Initialize the count
//Construct a Facebook URL
$json_url ='https://graph.facebook.com/'.$page_id.'';
$json = file_get_contents($json_url);
$json_output = json_decode($json);
//Extract the likes count from the JSON object
if($json_output->likes){
$likes = $json_output->likes;
}
//Printing the count
echo 'TechRecite.com has '.$likes.' Facebook Fans';
?>
Source: http://www.techrecite.com/get-facebook-likes-count-of-a-page-using-graph-api/
I am using the Foursquare API to request information for my users.
It says to make a request to get user info like this,
https://api.foursquare.com/v2/users/self?oauth_token=TOKENHERE
So I am doing it like this,
$fsUser = file_get_contents("https://api.foursquare.com/v2/users/self?oauth_token=".$access_token);
When I var_dump I get null from the value I am saving it in, Here is what my full code looks like,
<?php
$client_id = "iwdhwouchweohcuwoehcowehcu";
$secret = "ojdwojwjwrhvo";
$redirect = "http://www.example.com";
if($_GET['code']){
//We need to hit up the authkey URL and get the key in JSON format
$authkey = file_get_contents("https://foursquare.com/oauth2/access_token?client_id=".$client_id."&client_secret=".$secret."&grant_type=authorization_code&redirect_uri=".$redirect."&code=".$_GET['code']);
//We then need to decode it and store that key in a variable
$auth = json_decode($authkey,true);
$access_token = $auth['access_token'];
//we then look up whatever endpoint of the api we want
$fsUser = file_get_contents("https://api.foursquare.com/v2/users/self?oauth_token=".$access_token);
$user = json_decode($fsUser, true);
// $name = $decoded_userinfo['response']['user']['firstName'];
}
?>
When I var_dump $fsUser I get bool(false)
I have var_dump every variable with no issues till I get to $fsUser I can not get past this part...
You also need to use the version number (v) with your request.
Like this
https://api.foursquare.com/v2/venues/search?client_id=CLIENT_ID&v=20140806&m=foursquare
See documentation here.
https://developer.foursquare.com/overview/versioning
need to get the expanded url from a tweet. Heres my incorrect code:
$twitter_data = json_decode($rss,true);
for($i=0;$i<100;$i++){
$iurlx = $twitter_data['results'][$i]['entities']['urls']['expanded_url'];
How to fix this as simply as possible?
I have a group on Facebook where the users post funny pictures. I am developing a website that will present the posted pictures in a more organised and interesting way.
My approach is to use Facebook OpenGraph API.
I would like to know how I can obtain the first posts. Eg: the first 10 posts.
By default the graph API (https://graph.facebook.com/{group_id}/feed/) returns the posts sorted from LAST TO FIRST.
I have read the page about Pagination (http://developers.facebook.com/docs/reference/api/pagination/). So, I know about offset and limit parameters.
There appears to be no method of sorting the feed in any other order.
The only approach I can see it to download the whole feed and take what you need...
// Set your access token here...
$accessToken = 'XXX';
// Set your GroupID here...
$groupId = '123';
// Set the number of feed items required here...
$qtyRequired = 10;
$url = 'https://graph.facebook.com/v2.2/' . $groupId . '/feed/?limit=100&access_token=' . $accessToken;
$feed = array();
while ($url) {
// Get the data from Facebook.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url
));
$data = json_decode(curl_exec($curl));
// Store the feed to $feed.
if (is_array($data->data)) $feed = array_merge($feed, $data->data);
// Load the next page or quit.
if (isset($data->paging->next)) $url = $data->paging->next;
else $url = false;
}
// Feed will contain the oldest feed items.
$feed = array_slice($feed, -$qtyRequired);
You might be able to speed it up by specifying the exact fields you need.