Facebook on successful login callback function? - javascript

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

Related

I need a way to get updated oauth tokens for google photos

I'm currently working on an application for myself in which I need access to my own photos/albums on Google Photos. I have gotten by using the oauth 2.0 token generated in the playground, but I'd like to get a more permanent solution that does not require me manually regenerating the token. Is this possible with Google Cloud? The app is meant to run in daemon, so this makes any option with consent pages unusable. The scopes I'm using are:
https://www.googleapis.com/auth/photoslibrary.sharing
https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata
https://www.googleapis.com/auth/photoslibrary.readonly
I have tried using the https://accounts.google.com/o/oauth2/token and https://accounts.google.com/o/oauth2/auth endpoints to generate one programatically, but the only minor success I had was /auth sending me to a consent screen. I've also looked at using the refresh token given by Google Oauth playground with no luck there either.
Just looking to see if there is anything that I am missing.. This is my first post on stackoverflow, so please let me know if you need any more information.
I was unable to make it an internal app as it was for personal use and not for an organization.
Solved this by first using the google api package to create my own access/refresh token for my oauth client, then calling the https://oauth2.googleapis.com/token endpoint each time to generate a valid access token. I hope this can be helpful to someone else!
According to the setup documentation, as long as your app is marked as internal, you should not need to verify the app and can use it without the consent screen.

Is it possible to get a list of users from Directory API using only api key in a string?

I keep getting in to a loop of only seeing google's OAUTH documentation when searching for this but I don't want any user interaction. Maybe it's not possible. I want to do something like the code below in a http GET like you do with the maps API and receive a JSON reply
https://www.googleapis.com/admin/directory/v1/users?domain=MYDOMAIN&maxResults=200&key=MYAPIKEY
When I try something like the above I get 401 login required. I'm using vue-resource to make the request if that is relevant.
If it is possible could someone post an example of a correctly formatted request?
Based on the documentation available at https://developers.google.com/admin-sdk/directory/v1/guides/manage-users you should be able to do this with a simple get request however it MUST be authorized with OAUTH 2.
As stated at https://developers.google.com/admin-sdk/directory/v1/guides/authorizing "Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported."
I haven't used vue-resource before however I know that the Chrome plugin Postman has an authorization option to target OAUTH2.0 which should be a good place to start and perform a quick proof of concept.
Once you have the proof of concept working and understand how to interact with OAUTH you can look at implementing it in your app.

Automatically access my Google Analytics and display chart publicly on my website

I'm having some difficulties in figuring out the best way to do this:
Using Google Analytics API, or similar Google API, I would like to track a user's activity from the moment they access the page until they reach an end page, which is gonna show them back some charts with THEIR activity on my website. (Nothing too detailed, just how long they've been on each page, how many session etc.)
So far, I've managed follow the Embed API example to access THE USER's Google Analytics account and draw a chart by asking for permission, however when it comes to showing data from MY account I just can't seem to figure it out.
I want my website to automatically use my account (or service account) and draw some charts from my google analytics data and show it to every user.
What would be the best way to approach this? I've read something about access tokens but I don't know if that's the solution. Moreover, my hosting is a shared host and I don't think it allows installing Python Modules like in this example.
Cheers for the help!
If you want to show the user your data, you will have to perform the authentication on the server side. There is no way around this. It is after all, your account's data that they are accessing.
If you are unable to install Google's client library, you need to:
Get an access token using cURL (see how here)
Use that access token to perform server side authentication for the user (see how here)
The user should now be able to access your site without logging in, and see YOUR data.

Using jquery need to display facebook user name in html page

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');

Can I use the Facebook API to fetch images off my profile?

I have a blog. I want to add a bit of Javascript on my blog to fetch images from my Facebook profile and display them on the blog.
I have zero experience with the Facebook API, so at this point I'm just wondering whether this is possible. Can I run some Javascript on my blog to fetch images from my Facebook profile? Or does the Facebook API disallow such a thing?
I've only ever worked with Facebook API in PHP. However I know there is a JavaScript SDK available, which you can find information about here: http://developers.facebook.com/docs/reference/javascript/
You'll probably have to do the following:
1) Setup a Facebook application
2) Make it request permission to your photo galleries and offline access (for non-expiring token)
3) Retrieve the access token.
4) Use the call functions to get what content you want using the access_token to prove who you are.
Unfortunately I can't help anymore than that.

Categories

Resources