How to get latest 10 post feeds from facebook? - facebook

I know this question has been addressed many times but I am still facing problems, So I wanted to ask here if anyone can help.
I used facebook SDK to get the latest posts, here is the code below:
require "facebook.php";
$facebook = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => YOUR_APP_SECRET,
));
$pageFeed = $facebook->api(THE_PAGE_ID . '/feed');
Then I print_r the results but I am getting feeds like [story] which contains information like I have added someone as a friend or I have post somewhere, but there is also an attribute [message] which contains my reply on some post.
Now 1st thing I am getting only 4 feeds where is I want 10 feeds.
2nd thing is what information I shall extract to show on my website as latest post feeds (story, message or some other attribute)? Keeping in mind that I do not have both of these fields in every array.
If there is something I may not have mentioned here kindly do ask.
Thanks.

You have to use posts instead of feed because feed includes user postings too.
You can test it in Graph Explorer with <your page id>/posts?limit=10 to get last 10 posts of your fanpage.
So your code should look like
require "facebook.php";
$facebook = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => YOUR_APP_SECRET,
));
$pageFeed = $facebook->api(THE_PAGE_ID . '/posts?limit=10');

Related

Facebook Graph API search posts with picture

Im using the Facebook php API in order to search public posts with a specific hashtag in it.
Here is my code:
<?php
require 'facebookauth/facebook.php';
$facebook = new Facebook(array(
'appId' => 'myappid',
'secret' => 'myappsecret',
));
$query = urlencode('hashtag');
$type = 'post';
$ret = $facebook->api('/search?q='.$query.'&type='.$type.'&limit=10000');
echo json_encode($ret);
?>
My problem is that the above code doesn't return the posts that have an image attached.
I am posting from my profile a public post with the hashtag that im searching and if its only text i see it normally in my query results, but if i try to attach an image an write the same text it isnt returning me my post.
Can anybody help?thanx!
I also faced the same problem, it is because a post with an attached picture is no longer considered as post but as a photo contained in the timeline pictures album which one is not searchable through the search api. Can't wait for real hashtag search reachable through the api.

FB Graph API: Mutual Friends returns empty array

I am having an FB app and I want to find mutual friends between 2 users using my app.
When I use Graph Explorer for my app to find the mutual friends between 2 users connected to my app, it returns the correct results.
However, when I run the same query on my facebook php sdk, I get empty results. This is my code:
$fb_app_id = $this->config->item('facebook_app_id');
$fb_secret = $this->config->item('facebook_secret');
$facebook = new Facebook(array(
'appId' => "$fb_app_id",
'secret' => "$fb_secret",
));
$mutual_friends = $facebook->api("/802150300/mutualfriends/626070638");
$mutual_friends is an empty array here. Any ideas why I am getting it empty?
I don't think the facebook API allows you to get mutuals friends between any two friends. You can only access how many mutual friends you and another friend have.

Issue : Login with facebook

This is my first time to try integrate my page with facebook login. I using the way shown in http://www.domagojsalopek.com/Details/Create-a-Registration-and-Login-System-using-Facebook-Registration-Plugin/21.
I did exactly the same as in the tutorial. I even downloaded the sample and tried, yet it did not work.
But once I filled in all the detail and clicked the 'Register' button, it went to 'Server Error' page. I found that the error came from the following line in register.php
$facebook = new Facebook(array(
'appId' => FB_ID,
'secret' => FB_SECRET,
));
Note: I had replace my ID and Secret in config.php.
I had the solution already. In the sample code it does not include the facebook.php.

Can't understand script to create album, and upload photo to facebook fan page

I'm following this tutorial, http://www.webspeaks.in/2012/02/create-album-and-upload-photo-to.html to upload a photo to a facebook fan page album. The album is also created by the script.
But, the problem is that I can't understand somethings, or facebook changed the process, and the tutorial is not updated.
According to the tutorial, this page: https://developers.facebook.com/tools/explorer?method=GET&path=me%2Faccounts should return a json data, with the token.
But this, is the kind of data that I get, and it shows only Apps, not Fan Pages.
{
"name": "app name",
"category": "Application",
"id": "appid"
}
Another doubt, is that, if I want to upload photos to a facebook fan page, what should I put on these lines?
$facebook = new Facebook(array(
'appId' => '<app_id>',
'secret' => '<app_sercret>',
'fileUpload' => true
));
I can't understand this. I really need to setup a new application, that will be used to upload the photos to the fan page?
Thanks for any clarification.
Your must add permisson "manage_pages" when your access token, if your want to get list of fun page in answer.
$facebook = new Facebook(array( 'appId' => '<app_id>', 'secret' =>
'<app_sercret>', 'fileUpload' => true ));
You must create your own application, if your want to use grap api - https://developers.facebook.com/apps

How to upload custom app image (tab_image) for Timeline Page tabs via API?

Facebook released the new Timeline for Pages today. Apps installed to pages as "tabs" now appear above the timeline with a 111px x 74px size thumbnail "app image". You can customize this on a per-page level (just like the custom tab name) if you navigate the Facebook Page admin interface.
You can update the tab's "custom name" via the Open Graph API, but they do not appear to have updated their API docs to show how to upload a custom tab_image (assuming they will). Is it possible now but undocumented? Has anyone figured out how to do this yet?
Updated 2016:
With the latest Open Graph 2.5 API tabs endpoint and PHP SDK 5, the code should look like this:
<?php
$fb = new Facebook\Facebook([/* . . . */]);
$response = $fb->post(
'/{page-id}/tabs',
[
'custom_name'=>'My Custom Tab',
'custom_image_url'=>'http://publicly.accessible/image.jpg',
'app_id'=>'{app-id}',
],
'{page-access-token}',
);
Original 2012 post:
I figured it out, it's just like uploading an image. The field is called "custom_image". Presumably they will update the documentation soon. It's nice they enabled this API hook so quickly with the new release!
Here's how to do it with the Facebook PHP SDK:
<?php
$page_access_token = 'XXXXXXX'; // you'll need the manage_pages permission to get this
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
'fileUpload' => true, // enables CURL # file uploads
));
$facebook->api(
'/PAGE_ID/tabs/TAB_NAME', // looks like "app_xxxx" where xxxx = APP_ID
'POST' // post to update
array(
'custom_image' => '#' . realpath('path/to/my/file.jpg'),
'custom_name' => 'My App', // give it a custom name if you want too
'access_token' => $page_access_token // access token for the page
)
);
Cheers
As you said Timeline for Pages is just announced and it's too soon to say it'll be possible via API. Currently it's not possible even in settings of your App in Developer Application.
This information is simply not yet documented in help center or Graph API documentation.
It's also way soon to say someone have discovered if such functionality exists...
We all should wait a bit and probably file bugs which may get some response from officials confirming, rejecting or adding this to wish list.