How can I get a link to a Facebook or Twitter avatar by username? - facebook

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.

Related

Creating a Facebook App

I am building a website for a client. He has a Facebook page for his business. On the homepage of his site, he wants a feed that will pull in all the updates from his business' Facebook page.
Now, I felt this would be very easy to implement (maybe it is) but I have scoured the Facebook API for any simple way to do this. I am having a lot of trouble understanding which way I should do this. I've settled on using JS to access it, but have no idea where to go from there.
Do I need to create an app? If so, which options do I select so I can access the clients facebook page?
How do I get my app that I've created to show up so a user can authorize it? I have so many questions, and Facebook isn't very good at giving me answers.
Any help is greatly appreciated.
I would suggest you just use the facebook page's RSS feed.
Example
Take his page URL e.g.
https://www.facebook.com/pages/Lazery-Attack/6001014870
Take the number at the end of the url off, and plug it into the facebook feeds URL e.g.
https://www.facebook.com/feeds/page.php?format=rss20&id=6001014870
Voila, you now have an RSS feed you can integrate into the website you are building.
URL Breakdown
The URL is broken down the following way:
https://www.facebook.com/feeds/page.php?format={feedFormat}&id={PageID}
Vaid feed formats are:
RSS - rss20
Atom - atom10
JSON - json
Other Examples
Atom
https://www.facebook.com/feeds/page.php?format=atom10&id=6001014870
JSON
https://www.facebook.com/feeds/page.php?format=json&id=6001014870
Take a look at the facebook API, right here: http://developers.facebook.com/docs/reference/api/page/
You can give it a try here:
http://developers.facebook.com/tools/explorer/?method=GET&path=19292868552%2Fposts
The like box: http://developers.facebook.com/docs/reference/plugins/like-box/ also has the latest posts available
The simplest way is to add a Like Button to the page and make sure "show Stream" is checked on as this will show all recent posts. You can customise the appearance also (e.g. width, height etc).
No App or messy API calls needed!
Try it out here and simply paste the resulting code into your webpage:
http://developers.facebook.com/docs/reference/plugins/like-box/
Not an app, but the Facebook Social Plugins over here at Facebook For Pages

Share bought products from order on buyer's Facebook wall

The company I'm currently working for wants to create a button that lets people share their order on Facebook after they've paid, but with the deprecation of the "Share" button I don't really know how to do it.
The "Like" button does not seem fit for this. Any ideas, anyone?
There are a few ways to go about this.
You can use the standard sharer. This is good for one-off sharing or in cases where you don't have control or don't want to control how the share is rendered and you want Facebook to handle it.
http://www.facebook.com/sharer.php?u=<url to share>&t=<title of content>
It won't require you to have an app ID but you also won't get a nice control panel for your applications sharing history/insights. You can query and get some information about the URL your sharing though by looking through the open graph.
I.E
https://graph.facebook.com/?ids=http%3A%2F%2Fwww.cnn.com
https://graph.facebook.com/comments/?ids=http%3A%2F%2Fwww.cnn.com
You can set the URL and Title of the content. The sharer will then look at the metadata on the webpage your sharing to determine the contents of the share. More below.
You can also use the Feed dialog. Which comes with more customization options. The Feed dialog is the best option if your integrating sharing as an integral part of the application. I think at minimum you need to include the app_id,redirect_uri and link property. Look through the properties here. You will need an app ID to use this feed dialog and if your using the JS api you need to authenticate the user too. You can also invoke the dialog directly through a direct url where you don't need to pre-authenticate the user.
With either sharing method, you may wish to include custom open graph metatags on your webpage. This way you can influence how the Facebook scraper makes your share. You can set some default (pre-accepted by Facebook) open graph metatags on your page. Or you can create your own set now in the dashboard. In the Open Graph dashboard on Facebook you can customize how Facebook is supposed to read and interact with your metatags.
You can debug your pages open graph metatags by passing your URL through the debugger.
I.E
http://developers.facebook.com/tools/debug/og/object?q=www.cnn.com
This will give you, for example, JSON or an HTML representation of how FB sees the page.

Getting facebook profile picture

i need to get the facebook profile picture of anyone by passing their id. But i no need to use facebook API or Graph anything else.. Just i need to give the url with that id.. Is it possible to get the profile picture in this way? I tried in google but i didnt get it. If anyone knows this please respond me...
Well, I think the only options available are:
https://graph.facebook.com/[PROFILE_ID]/picture (You can include this URL inside a tag and it will work).
Scrap yourself the page corresponding to the profile, i.e. http://www.facebook.com/profile.php?id=[PROFILE_ID] and get the URL of the picture there.
I would suggest you to use the first one, because it gives you more flexibility about the picture size (?type=small, ?type=thumbnail, etc).
Edit
Keep in mind that this answer is from 2011, and Facebook makes changes in its APIs frequently.
Apart from using Graph API as already mentioned above (https://graph.facebook.com/[PROFILE_ID]/picture), there are a couple more ways:
FlipTop has a service that pulls up all sorts of information on Facebook users, including direct CDN URLs (e.g. https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/275588_504804917_147319_n.jpg) of profile pictures. (Link to API documentation)
Cloudinary has a similar service, but with hosting thrown in the mix. They do require you to open an account, but it's free. Then you can use their CDN URL format to link to any picture like this: http://res.cloudinary.com/[YOUR_ACCOUNT]/image/facebook/[PROFILE_ID].jpg (Read more here)

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!