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!
Related
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.
Firstly i know that the documentation provided by Facebook says that fb:multi-friend-selector can be used in pair with fb:request-form and that it could only sends inviations or requests.
I have more specific need and that is not only to make invitations/requests but also along with the previous to post something on selected friends walls.
I've tried everything but i cant take the id's selected from the fb:multi-friend-selector, so i'm unable to make this posts.
The doucmentation for fb:multi-friend-selector says: This interface includes a series of which are included for selected users in the form that gets submitted to your action URL.
Is it somehow possible to catch this id's?
I'm working on my app in C# .net.
I read in some of the previous posts that is treating problematics similar to mine that is impossible to do this, but i found application that works perfectly in way that i want to make my application.
Thanks in advance,
Ivan
You can access the selected friend's id in the page that you are providing in "action" of fb:request-form.I am working with PHP so i am able to get those selected friend's id as $_REQUEST['ids'].So try some equivalent methods in c# for this.And if you get the friend's id you can publish to their wall.
How can I get a link to a Facebook or Twitter avatar by username?
For Facebook the image is publically availible and can be seen at: http://graph.facebook.com/username/picture
For example, here is mine: http://graph.facebook.com/totten/picture
You will notice that the url above actually gets forwarded to another caching url. Don't save the long url (http://profile.ak.fbcdn.net/....) save the short http://graph.facebook.com/ one. The other, longer url, could change and break.
If you want to display that url in a web page you just need to do the following:
<img src="//graph.facebook.com/totten/picture" />
Which gets you: http://graph.facebook.com/totten/picture
Thats it, no complicated API or authentication is needed.
For twitter you need to use the api: http://apiwiki.twitter.com/w/page/22554755/Twitter-REST-API-Method:-users%C2%A0show
you have to use facebook's graph API to get profile pictures. You'll have to register your app with facebook to get an API key, and then you can access most of the information on a given user's profile.check out their developer page to see some examples
Twitter just changed the way they handle API call. Looks like you'll have to register your app with them as well to get access to the avatars. I haven't used the twitter API since they changed it, so i'm not a sure about what goes on, but check out the docs page to read up on what you'd have to do.
hope this helps!
Some programming paradigms (Razor in ASP.NET or ASP.NET MVC 3, for example) have their own helpers to work with social media. If the paradigm you are programming in does not have helpers, you will have to access the FaceBook and/or Twitter APIs and use them to get the "avatar".
I have not played with Facebook, but the Twitter avatar link is provided on the user's profile, when you get it.
With regards twitter, I was able to get mine by visiting my profile page:
https://twitter.com/<USERNAME>
From there, you locate the <a> tag with the class ProfileAvatar-image and extract the href attribute. I was able to use that link on a separate site to import my avatar from Twitter.
I did all this manually, but it would be relatively easy to set up a script that used the username to request the profile page and isolate that link.
I am completely new to facebook api and working on a very small project. Before getting into details of their api doc, I wanted to ask a quick question.
My application needs login with a facebook userid/password, go to a friends wall / groups wall, crawl through all the wall posts and dump them in database for further analysis. A simple http client would do the trick if facebook weren't completely unusable without javascript. Since its going to be a desktop app, I am reluctant to go for a full fledged server based app.
So what should be the simplest way of crawling through FB friend / group wall? Please correct me if I'm asking the wrong question because I have Zero FB knowledge.
PS: I would like a java based library / wrapper but any language would do...
the current api has some serious bugs. Either you only get 50 items from the wall or only the items of the last 30 days, which comes first.
Please check the facebook developer bug list first. Developer Bug list
The Facebook Graph API would be the best solution, but if it is buggy, as Herr Kaleun pointed out, and you need more than 50 items or 30 days of posts, then I have another idea.
It may not satisfy your distribution requirements, but if it does you can implement this as a GreaseMonkey user script. GreaseMonkey is a system for web client automation that is javascript-aware. It lives in the web browser and is written and controlled by javascript, and can also pragmatically simulate a user affecting javascript. GreaseMonkey is a Firefox plugin, but Chrome also has native support for user scripts (the language is slightly different, but most GreaseMonkey user scripts will work in Chrome).
Ok, on a quick search, It seems that the answer is the FB Graph API. I can see there are wrappers of graph api in almost all language. For Java, I found the RestFB & BatchFB. Please feel free to refer to any more useful / advanced api if available.
UPDATE:
I couldn't find any extended permission set to access a user's group wall / a user's friends wall? is it atall possible with an Application?
Prerequisites:
Your group needs to be publicly viewable You need to have signed up to make a Facebook app, in order to get the APP_ID AND SECRET_KEY.
Then, (example in PHP, but should easily be transposed to another language):
$url =
"https://graph.facebook.com/{$group_id}/feed?access_token=APP_ID|SECRET_KEY";
$data = json_decode(file_get_contents($url));
foreach($data->data as $d)
{
?>
<div>
<a href="http://facebook.com/profile.php?id=<?=$d->from->id?>">
<img border="0" alt="<?=$d->from->name?>"
src="https://graph.facebook.com/<?=$d->from->id?>/picture"/>
</a>
</div>
<div>
<a href="http://facebook.com/profile.php?id=<?=$d->from->id?>">
<?=$d->from->name?></a>
on <?=date('F j, Y H:i',strtotime($d->created_time))?>
<br/>
<?=$d->message?>
</div>
</div>
<?
}
This will get the wall posts. As far as limits, I don't know.
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