Retrieve photo albums from Facebook using Graph API - facebook

My head is currently going nuts trying to figure out the most effective way to retrieve the albums from a fan page I own, to an online page. I've seen a code that used FQL and it worked, but it's too slow and apparently it's outdated.
I've browsed around and came across the Graph API concept but it looks a bit hard to understand. By the way I already have an app registered and I also started to search around the Graph Explorer but I can't come to a conclusion.
Are there any tutorials out there?
EDIT: I've tried this code:
<?php
$album_id = 'myalbumid';
$access_token = 'accesstoken';
$url = "https://graph.facebook.com/{$album_id}/photos?access_token={$access_token}";
$image = json_decode(file_get_contents($url));
foreach($image->data as $img){
echo "<img src='{$img->images[6]->source}' /> ";
}
?>
And it works, it displays all the photos from a given album. But what if I want it to display all albums (including thumbs) and the user navigates through them?

Requesting the following will give you a reply with all albums and photos in those albums:
https://graph.facebook.com/CocaCola/albums?fields=photos
You'll want to replace CocaCola in the example with your own page name or ID.
This is called nested requests or field expansion. There are several detailed examples on the Facebook Documentation site.
A few comments for you to help you along the way:
Calls to retrieve page objects don't need an access token so long as the page does not have age and/or country restrictions. Unless you legally need them, I wouldn't recommend adding restrictions.
Using file_get_contents() is okay for sandbox testing, but you should use the Facebook PHP SDK for production code.

Related

Crawl Public Facebook Posts

I made a website where people can post links for other websites and then the backend generates a preview of the link (by using curl and parsing out the open graph tags available on most websites / by picking the first image, html title etc). Now, fine after some tweaking but sometimes I get some kind of rate limit.
Here is one example of a link I want to parse: https://www.facebook.com/HBR/posts/10157131816732787
I can parse it 4 ou 5 times and get a title, image etc but then if I repeat it I get sent to the login page of facebook. How can I avoid this?
I tried to parse the link at https://developers.facebook.com/tools/debug/sharing however it says "Facebook URLs cannot be crawled". So my question is: how am I even supposed to parse those links if they don't even allow it on their debugger?
Is there any kind of API that allows me to get this information without user login? I don't want to parse entire facebook pages, profiles etc, just get a preview for a link that my users might post on the website.
You MUST use the Facebook Graph API if you want to get data of Facebook Pages (or anything else on Facebook), scraping is not allowed.
In order to get data of Pages you do not own, you need to apply for Page Public Content Access: https://developers.facebook.com/docs/apps/review/feature/#reference-PAGES_ACCESS
An App Access Token (without Login) is sufficient in that case.
API Reference for Pages: https://developers.facebook.com/docs/graph-api/reference/page/
I dont think show.You can crawl post on public group using python selenium and beautiful soup

How to show facebook group wall/posts on the website in a feed

I am new here, I have read through all possible solutions to this and I can't find anything that answers our problem. I am an admin for a facebook group and we want to show the wall posts on a feed for the charities website. We have allowed anyone to see the posts on the facebook group settings. However, we cannot get it to work on the website feed to show the wall entries.
One problem maybe that no one has the original settings when the group was set up. There are now group two admins but both admins don't have any setup logins to see data from the group. Can we change this so we can get all the data that is available? We don't have any access to group users and data that is usual with pages so I think we are missing something major here.
The group is https://www.facebook.com/groups/borntoosoonkh/
Any help for a workaround on the access issue and also if it is possible to show wall posts from a group on a website feed.
Really hope you all have brilliant ideas.
Thank you for reading and your time.
one last thing, please.......I know that you cannot like a post unless you are a member of the group but I also can't find a join button for people to request membership.
You can programmatically access the wall posts of a group, but you'll need an access_token, acquired from a Facebook Connect button.
For an example, see the Graph Api Debug Console: group Born too soon
read this it will get you there
https://developers.facebook.com/docs/graph-api/reference/v2.5/user/feed
$request = new FacebookRequest(
$session,
'GET',
'/groups/feed'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
// handle the result
I am currently researching the same problem. You have to find a way to get an access token without a specific user. How to do this? Still working at it. But like the user above said get it from the Gragh API explorer on the facebook developers site, problem is it times out.
What I did was create a facebook app. Use this site below as a guide...
http://ranacse05.wordpress.com/2011/02/04/show-facebook-group-wall-on-web-site/
its old but it should bring you up to speed. And you can have something like the code below some where:
$token = $access_token; //$access_token is created in facebook app
$token ='?access_token='.$access_token; //append '?access_token field' from included php file
$url1 = 'https://graph.facebook.com/'.$group_id.$token;
$des = json_decode(file_get_contents($url1));
Wallflux.com provides feeds for facebook groups, not sure about your question about the join button, though.
warning, im affiliated with Wallflux

Get Facebook Page Wall Stream

I want to get the posts (only from the band, not others) from a Facebook Page Wall (its a Band, so no private profile) and publish it on MY own site.
I hoped to get the Posts as XML or JSON and then parse them.
So I wanted to use Facebook as a news System.
But I didn't find a solution - I don't want to have the user to log in with his account to see anything - it should be just a public stream.
The only idea I found was to use twitter as an export mechanism, but that's kind of elaborate.
Does anybody have an idea?
You could use the Facebook php sdk: https://github.com/facebook/facebook-php-sdk
It ends up looking like this:
//
include('facebook.php');
$fb_config = array(
'appId' => $yourAppId,
'secret' => $yourSecret,
);
$facebook = new Facebook($fb_config);
$feed = $facebook->api("/{$nameOfFaceBookPage}/feed");
That will give you an array of feed stories.
I assume you created a facebook page for your band and it has url in such format:
http://www.facebook.com/pages/<band_name>/<page_id>
In this case you can read wall posts in json format using Graph API (no login required):
https://graph.facebook.com/<page_id>/feed
If you only want posts from "me", can't you just use the Like Box social plugin and show the stream? This plugin will only show posts from the page owner.
http://developers.facebook.com/docs/reference/plugins/like-box
I am developing a similar app and after a lot of searching finally accomplished
https://graph.facebook.com/194466683916784/feed?access_token=AAACTzPZAxblQBAHND7fo1rA58VqQawuJb806Q6BeIFhTroyGSYIe5i0R5fZAZBtffNvkkZB7ayvV7Vw7j7ZBf7vGt6xHx2gjx4FhO8d27sAZDZD
enter your page wall id after .com and in the access token get your own access token from Graph - API explorer
Then exchange that token for a longer for a longer lived one that is for 60 days and you are good to go
Some time ago I had your same problem and I was looking for something very simple to publish feeds of facebook pages, but I didn’t find any solution on the web.
What I want to achieve are the post (only from my personal fan page, not the other) of the bulletin board (facebook wall) of a FB page (this is a fan page, not private profiles) and publish it on my site.
I was hoping to get the posts in JSON or XML format and then encode them so as to use FB as a news system. Unfortunately I haven’t found any kind of solution because I don’t want the user has to log in his account to see something so it must be a flow of pubblic feed.
So, I decided to code the plugin. Here the link to the tutorial:
http://www.lorenzodedonato.com/freebies/facebook-plugin-per-visualizzare-i-post-della-bacheca-di-una-pagina-fan-creato-in-php-json/

Choose Graph API or old REST API for Facebook application

I should have asked this in Facebook developer forum instead, but somehow I can't register to the forum and the Facebook connect feature is not working at the time I'm writing this.
Anyway, I am still confused whether to use Graph API or the old REST API for my Facebook app.
Generally, this is what I want to achieve in my app:
Get profile picture and name of the user.
Get profile picture and name of the user's friends who are also using my app.
Post into the user's stream.
Allow users to invite their friends to use the application.
Can someone provide me an insight, which one is better for my application?
As Renesis said, the Graph API covers exactly what you need for the first three steps.
For the fourth point, I've been looking at the API extensively for my own apps and have found out how to do it via FBML with the following code:
<fb:serverFbml>
<script type="text/fbml">
<fb:fbml>
<fb:request-form
method='POST'
type='join my Smiley group'
content='Would you like to join my Smiley group?
<fb:req-choice url="http://apps.facebook.com/smiley/yes.php"
label="Yes" />'
<fb:req-choice url="http://apps.facebook.com/smiley/no.php"
label="No" />'
<fb:multi-friend-selector
actiontext="Invite your friends to join your Smiley group.">
</fb:request-form>
</fb:fbml>
</script>
</fb:serverFbml>
http://developers.facebook.com/docs/guides/canvas/#requests
It seems as though Scott's incorrect when he says Graph incorporates everything the old REST API has:
"We are currently in the process
upgrading our core server API from the
old REST API to the more modern Graph
API. However, most of the methods
required for canvas applications to
integrate with Facebook have not yet
been upgraded to the new API. For the
time being, we recommend you continue
using the old REST API in canvas apps
instead of the new APIs for the sake
of completeness."
(I can only post one hyperlink, so it's the same one as the #requests hyperlink but in the 'Making API calls' section)
Not sure if this is the case with other methods of integration such as web or desktop apps, but so far it seems as though the Graph API has a little bit of catching up to do!
Edit:
To list the profile pictures of a user's friend, use the following:
Assuming you've already got the current user's ID
https://graph.facebook.com/**USER-ID**/friends?fields=picture,name&access_token=**ACCESS-TOKEN**
This will provide a JSON object with a list of the current user's friends containing the UID, name and a link to the small version of the profile picture.
I haven't found a way to retrieve the large picture version in a search yet so with that method, if you wanted the large version, you'd have to iterate through each user and use this:
https://graph.facebook.com/**USER-ID**/picture?type=large
Get profile picture and name of the user.
http://graph.facebook.com/[uid] for the name and http://graph.facebook.com/[uid]/picture is an always up-to-date link to the current picture. Also, if you have an access_token, you can query http://graph.facebook.com/me for data on the current user, whoever that is.
Get profile picture and name of the user's friends who are also using my app.
Not sure about how to get the specific friends only, maybe using FQL. However, note that you can get specific fields in the friends list (defaults to just name and id) by adding a fields parameter: .../friends?fields=id,name,picture
Post into the user's stream.
Perform an HTTP POST to http://graph.facebook.com/[uid]/feed with a body parameter. (see http://developers.facebook.com/docs/api#publishing)
Allow users to invite their friends to use the application.
Sorry, not sure on this one...
Use the Graph API as it incorporates everything that the old REST API had. Plus The new API is RESTful, and results are returned in JSON which is good!

Where is the Facebook Status feed URL these days?

I know that it was previously possible to display your most recent Facebook statuses on your website as an RSS feed, but it seems they've changed their setup and I can't figure out where to find the feed anymore....
I saw some people searching for this a while ago, but since Facebook just released their new layout, I didn't know if this might have changed again.
Any help would be greatly appreciated.
Try this for a feed in JSON-format.
http://graph.facebook.com/[uid]/feed
Facebook appears to have killed all the public status feeds in the name of user privacy. The only way to fetch it is to build a facebook application that gets your status updates, and then associating your facebook account with that application to give it permission to access your status updates so it can put them somewhere else.
Thankfully, someone has already done that for us. Just go to http://apps.facebook.com/statusexport/ while logged in to facebook and grant the app permission. Then it will give you a public URL to an RSS feed of your status updates.
Just keep it simple... This is an easy way to load your latest status(es) using graph.facebook.com through curl / php. Includes a quick simple function.
Easiest way to load your latest facebook status
I found this site which you authenticate, and it will then give you a working rss feed.
I have found that it does have some limitations, but you can see it here:
http://www.fbrss.com
If you wan't to display status updates only, you can use:
https://graph.facebook.com/[uid]/posts
This URL will return a JSON string of user [uid]:s status updates.
To get your status feed, follow these instructions:
Log into Facebook
Go to http://www.facebook.com/notifications.php
Click the link titled "Your Notifications" at the bottom of the box to the right of the list of notifications
That will bring you to a feed of your notifications, which is not what you asked for. This url will be something like feed://www.facebook.com/feeds/notifications.php?id=XXXXXX&viewer= XXXXXX&key=YYYYYYYY&format=rss20
Change notifications.php to status.php in the URL (preserving all the URL parameters).
That should be a feed of your status updates.
Start at http://www.facebook.com/notes.php and click on the "My Friend's Notes" link. Change the friends_notes part of the url to friends_status, and you should be good to go.
Programmatically specifying user to query status updates for
(Note: This is a server-side solution)
It's possible the feed you're looking for has been deprecated for security purposes.
Alternatively facebook FQL on the Status table might provide an answer because it allows you to specify the user ID (for example, your own) for which to retrieve status updates, and a time frame can be specified to limit them as desired.
A raw fb FQL query example, for status updates:
select uid,status_id,message
from status
where uid in
(select uid2 from friend where uid1= uid)
AND time > {time in the last week}
The main FQL guide starts here.
Sample
Poking around the Internet you can pick up sample code of FQL code being called from PHP and other platforms.
PHP example:
<?php
$q = "SELECT name FROM user WHERE uid='$id'";
$query = $facebook->api_client->fql_query($q);
?>
The facebook client API library for your platform of choice can be downloaded and used to issue FQL statements.
--
There is also a Test Console hosted online for facebook developers to test API statements against their own account.
You can also use a RSS feed generator for your Facebook Statuses (or Photos) like the RSS Feeds application on Facebook.
It will help you generate a RSS feed for all your statuses and photos while maintaining the privacy modes.
Although, I am not a fan of the user interface the application has, but the functionality is what is awesome :)
Theres also anther way to do it..Which is simple and easy...its not an rss feed but a plugin can be developed to output as an rss...Theres a tutorial of it on http://Fourgefeed.com