Using jquery need to display facebook user name in html page - javascript

Using jquery (javascript) need to display facebook user name in html page using facebook user id. I am not using facebook api. Any one have any idea.

Without using the facebook API (Graph API or older facebook REST API) either javascript or PHP there's no way you can achive this.
Facebook needs to authenticate your application before you ask for data.
You can use fb:name from FBML (Facebook Markup Language) to achive it easily. But as recoomended, you should not use FBML for new applications since the recommended way is the new Graph API. FBML is in the process of being deprecated.
Using the new Graph API you can get the JSON object for the user by fetching https://graph.facebook.com/{userID}

You need to use the Facebook API as Facebook needs to authenticate your application's requests for user data. (http://developers.facebook.com/docs/api#authorization)
I recommend using the Graph API (http://developers.facebook.com/docs/api), but it takes a bit of work getting started.
I use the PHP SDK (http://github.com/facebook/php-sdk/), though others also exist and you can find them in the Facebook Documentation.
However, to answer your question better, If you have your authorization token you can make calls for example:
https://graph.facebook.com/me?access_token=<Your Access token>
would return a JSON object containing your basic information, including your name, birthday, and basically everything that appears on your profile.
Before doing anything you MUST register your own application at www.facebook.com/developers/
(Edit: I was not aware FBML was being phased out)

I know it's an old thread, but so that people doesn't get mislead...
There is NO need for Facebook to authenticate your application before you ask for data like user name because user name is public info and does not require permission. Just call https://graph.facebook.com/{userID} and you will get a JSON object. You can achieve this easily using jquery:
$.get("https://graph.facebook.com/{userID}", function (data) {
alert(data.name);
}, 'jsonp');

Related

Facebook Api to post use submitted image to a specific page

Here is what I am trying to achieve - I want to take input from my users as some text and image and post it to a page created by me. The user using the mobile app , does not have any any access to that facebook page. I want to post to that page anonymously on behalf of the user. The page is created by me so I should have access to it. I am really confused what to look for. I have set up an app in facebook developer from the same account who is the creator of the page and I can login user's and have their access token.By the way, if it's relevant I am building a hybrid app and using cordova facebook native plugin
This is the API call you need, there are code examples for several languages: https://developers.facebook.com/docs/graph-api/reference/page/feed#publish
Take a look at the code for the JavaScript SDK, just use that API endpoint with the correct parameters in your cordova plugin.
You need to use a Page Token with the manage_pages and publish_pages permissions. More information about Tokens:
http://www.devils-heaven.com/facebook-access-tokens/
https://developers.facebook.com/docs/facebook-login/access-tokens/

How to configure OAuth with Goodreads

I am building an app using HTML, CSS, and Javascript, and am trying to configure OAuth to use it to access data from the Goodreads API. I basically want to get a list of books that a Goodreads member has read in the current year and display statistics about the metadata of these books. I'm pretty new to Javascript and using API's and don't have a super good grasp on OAuth and API authentication in general so I would really appreciate it if it could be explained as simply as possible.
From what I understand I need to create a login button on my page that contains a link that looks something like this:
http://www.goodreads.com/oauth/authorize?oauth_token=SCDMymQWcIE8GnxmSA
When the user clicks this button they'll visit goodreads.com where they'll login to their account. After accepting the permissions, the user will be redirected to back to your site along with an access token that would contain the user's ID. At this point I would use the user ID to pull data about the books on their shelves.
I'm not really sure how to go about writing this in my Javascript file though. How do I go about authorizing via OAuth and storing the user's ID? From the Goodreads Developers group it seems like the Goodreads API uses OAuth 1.0 which I believe is relevant to how I will need to approach this.

What is the simplest way, using JavaScript, of fetching the latest post from a public Facebook page?

I want to fetch the text of the latest Facebook post from a client's public Facebook page.
Am I being dense, or is this ludicrously difficult?
From what I understand, I need to create an app, use the app ID and the secret to generate an access key... but the access key is only temporary, so I have to do something to create a permanent access key... which itself is not guaranteed to be permanent, and which anyone viewing my JavaScript code could copy anyway. It all seems so incredibly convoluted!
I don't want to have to create a dummy Facebook application, then go through the hassle of a full scale implementation simply to grab text which is publicly available to anyone with a web browser.
The same argument was made for Twitter auth and resulted in the development of the wonderful TwitterFetcher.
So, is there a very simple way I can grab the text of the latest public post from a public Facebook page?
You have two options.
First: You may use Facebooks Page Plugin (Docu)
Second: You could implement the logic server side to fetch the post. This can be done without additional user token, due to the privacy of the post (public).
(Docu)
It turns out that there is no public feed functionality as there was several years ago in older API versions. Every request needs an access token, even requests for totally public resources. This means that you do need to set up a Facebook app, even if it's a usless one.
Once you have the app's ID and secret, you can make graph requests, passing appid|secret as the access_token parameter instead of actually getting an access token.
This should only be done server-side, because client-side it will publish your secret.
So to answer my own question, the below will return a JSON object with the latest post's data, without the hassle of generating access tokens:
https://graph.facebook.com/[your_username]/feed?access_token=[your_app_id]|[your_secret]&limit=1
Note that the app_id and secret don't have to be generated by the same user whose public profile you're trying to access. So the following will also work to fetch Coca Cola's latest post:
https://graph.facebook.com/cocacola/feed?access_token=[your_app_id]|[your_secret]&limit=1
Thanks to this answer.

Generic Facebook User Access Token for public event search

I'm trying to create a Javascript application that has a filterable listing of certain kinds of public Facebook events. The thing is, the FB Graph API requires that you provide a User Access token in order to use the search for public events. I really don't want to make people log in to facebook in order to use the website, especially because ANY facebook user's credentials are sufficient to query the events I want to query (ie the search is independent of any user credentials, I just need them because the fb api requires me to have a user access token.)
Do y'all have any suggestions for a work around? I'm thinking about providing my own credentials securely, and just using them to make the actual queries. The thing is I would potentially need to be doing A LOT of queries per minute, so this might not be terribly realistic. Any suggestions would be helpful.
Simply do this server-side not client-side.
You just need an app token (no user token) to do this search, but using this client-side is a bad idea since it would expose your app token publicly.

Facebook on successful login callback function?

I'm using the facebook JS API to get some information from users when signing in to a product I'm making.
My question is this - how can I perform a function after they have given the application permission to use their data?
I don't see a callback function in their documentation, but figured there's an easy way to do this. Basically, I want to show a loading image until they've authenticated. Then, if they've given me access, I'll do some animation stuff.
Thanks!
Honestly, I'd steer clear of their JS SDK. It's almost as bad as their PHP SDK. What they really want devs to do now is utilize the Open Graph. Then you can use cURL with PHP or Ajax or even simple redirects with URI parameters. That being said, with either application, you should receive an access token after the user accepts permission requests. Once you have the token, you can do whatever actions you need. You can create your own callback to handle this.
Easy Open Graph debugger: http://developers.facebook.com/tools/debug
Graph API Explorer - this helped me a ton when I was first starting with the OG development: http://developers.facebook.com/tools/explorer

Categories

Resources