So version 2 of Facebook's graph API introduces app-specific IDs, to protect user privacy from spam or something like that. But they said that users who have added your app in v1 using a global ID will continue to send you their global ID in v2, to keep your app backward compatible.
This is all fine, but v2 of the api also forbids getting user data with global IDs. A call to the graph with global IDs from inside a canvas app gives an exception saying to use the app-specific ID instead.
I'm kind of at a loss here. I'm trying to get the basic information of a random subset of my app's users, to display to the current user, who isn't necessarily a friend. But most of my users have global IDs stored in my database because they joined a long time ago. It seems like if my app were new, all of the IDs stored in my database would be app-specific, and so I would be able to get their info. This indicates to me that it's not Facebook's intent to forbid me from getting the data I want. It's just impossible for me because of the unfortunate situation of having an old app.
Is there any way for me to get this data? I know I can revert to v1 of the graph but that will go away on April 30, 2015. I only want the most basic info, and I'm only displaying names.
I am using version 4 of the PHP SDK. My request looks like this:
(new FacebookRequest(
self::$session, 'GET', '',
array('ids' => implode(',', $userIds))
))->execute()->getGraphObjectList(GraphUser::className());
My session comes from calling getSession on the FacebookCanvasLoginHelper as shown in their docs, so I have a new access token and signed request.
edit
So, I rescind my question, because I'm dumb. Sahil is right. My problem was that I'm working in a separate app for testing (not an official test app, but an app I created a long time ago for testing) so the app IDs in question haven't actually added the app, so I can't get their info. Oops. Good reason to migrate to an official test app.
edit again
I un-rescind my question. Facebook is dumb. I created an official test app tied to my real app, and it is giving me an app-specific ID for myself, not the one given for the main app. I check out the page I had trouble with before, and the same exception:
Facebook\FacebookAuthorizationException: The global ID 693041250 is not allowed.
Please use the application specific ID instead.
The dev page on test apps says:
Test Apps share the same app-scoped User ID namespace as your production app making it simpler to debug issues with app-scoped IDs, or in cases where you use a copy of your production database for development.
This appears to be blatantly incorrect. I'm using a copy of my production database. I know my Facebook ID. It wouldn't even give my own ID that was given for the production app, let alone anyone else's. Does this new thing only work for brand new apps or something? I'm about ready to abandon Facebook development at this point for things like this.
You are correct in saying that-
users who have added your app in v1 using a global ID will continue to send you their global ID in v2, to keep your app backward compatible.
But this is incorrect: but v2 of the api also forbids getting user data with global IDs. A call to the graph with global IDs from inside a canvas app gives an exception saying to use the app-specific ID instead.
Of-course you'll get the user data with id returned by v2 API (be it global-id or app-specific-id).
Sorry but I don't really understand the SDK's syntax you've used (I don't like using SDKs), but I'm sure this will work. You can even test this in Graph API Explorer, just select your app from (top-middle) drop-down and call /v2/{user-id} of a v1 user and this will get you the result. You must be doing something wrong in your code.
Related
I have a website I'm working on. It enables users to register and post stuffs within the site. Can I get a link to some sort of api that allows people to add their facebook account (once) and then automatically post what they posted on my site on their facebook newsfeed (the sort of thing that happens when you connect your facebook account to your twitter account) .I've searched and can't seem to get exactly what I want
What you want is pretty common and if you searched you clearly didn't do a good job on the search.
Using the Facebook PHP SDK is pretty straight forward. There is a PHP Library available with a demo of the functionality you want. In your case you need to do some stuff more, so I'll explain globally what you should do:
Get the Facebook PHP SDK and load it into your website, determine what scope you need to perform the actions what you are going to do, in your case you need to have access to their timeline which is called the publish_stream scope. In order to get the Facebook PHP SDK working you need to create an app at http://developers.facebook.com
If a user grants access you need to save the authentication token that the user provides and save it in your database for later use. I'm not 100% sure how long they are valid, I think it's maximum of 30 days at the moment, but you have the ability to refresh the toking in the requests you make (correct me if I'm wrong, it's been a while..)
Everytime an action is done using the Facebook API you inject the usertoken in the request, thus performing the "post" action onto their timeline.
What you are looking for is pretty straight forward and easy to find..
I am trying to get a list of all Google Apps users of a domain onto a public PHP website (without visitors of the site needing to login or do anything). I have a basic understanding of what needs to happen but can't quite piece it all together. It can't be as hard as it seems to me... could it?
Authentication and Authorization:
I'm pretty sure it needs to use OAuth 2.0 ... but am unsure whether it needs 2 legged or 3 legged. I got another section of the site working with ClientLogin but that won't pull in Google Apps profiles, only user's first and last names (I need the other profile fields). I have set up the API access within the account and have that side of things all set (I believe).
I have found this page, which shows how to construct a URL request to get all Profiles (in every language except PHP of course) but don't understand how to implement this.
http://code.google.com/googleapps/domain/profiles/developers_guide.html
I also tried this example but it just gives me a 401 after I enter the credentials. http://gdatatips.blogspot.com/2008/11/2-legged-oauth-in-php.html
I don't know which frameworks or includes are needed to accomplish this either. I have tried zend, OAuth.php and a whole bunch of other bootstraps... but keep getting lost as to what each is doing.
If someone could help me by outlining:
Which files/framework I need to upload and include as a bootstrap
What variables within those files I need to update with the Google credentials
How I integrate the Google Profiles "Retrieve all Profiles" request with PHP
An ELI5 (explain it like i'm 5) overview would be very much appreciated... I'm sorry for my apparent incompetence, but I have been reading articles for nearly a week and have not gotten anywhere.
Thank you in advance for any help provided.
Good question.
You'll need to implement the Google OAuth 2.0 process as it's described here (experimental?), because someone (you) will need to give your app the initial permissions to access Google Apps API. Steps are:
Register your domain with google (don't remember the link)
Redirect/send browser to an authentication url: https://accounts.google.com/o/oauth2/auth, with the appropriate request params (see the first link). You'll need access_type=offline, your scope would be https://apps-apis.google.com/a/feeds/user/
Get a code back, then exchange for a refresh_token, an access_token, and a value specifying when the access_token will expire. Store these in a database
Whenever you need to make an API call, check if your access_token has expired or not, and refresh when necessary, which is what the refresh_token is for. The refresh_token is valid as long as you don't revoke the access you gave to the app.
OAuth Playground helps a lot. Good luck.
This could be me making extrapolations from the documentation (which given how it's organized, isn't too difficult to do) but did Facebook make some big changes to how application developers create and utilize test users?
To my recollection (and I last did this about a month ago), developers used to be able to go to a url from within a logged in account that would convert that user to a 'test user', who had no privileges in the public system but could serve as a test entity for publishing, getting permissions, etc. I had a test user setup via this method and had generated access tokens for him/her that were saved to the database.
Recently this all stopped working. My first instict was to print out the properties of the Facebook object I had created, and where once there had been the JSON decoded user data, there now was an exception from the CURL process that accessed the /me/ api endpoint.
Facebook GraphAPI – Uncaught EntCannotSeeExistenceException: The entity (class EntTestUser) backed by id 12345 cannot be seen by the current viewer 12345 (EntID: 12345)
Values obviously changed to protect the innocent. The userids were identical however, which made it strange that the user possessing ID 12345 for some reason had no rights to see 12345
I looked through the Facebook documentation and found their what seems to be their new logic for making the application itself create temporary test users and generate login URLs for them, something alot of people here are probably familiar with.
http://developers.facebook.com/blog/post/429
Has this system superceded the old one? It seems that acting on behalf of test user accounts generated via the old method is no longer permitted since they are not made "by" the application. I wrote some quick logic to test this new process with fixed access tokens and it worked - I should also mention that all the application logic functions as it originally did with no errors for real user accounts. Has anyone else experienced this with their Facebook api apps? Can we definitely say that these old access tokens/userids/accounts made via that old method are now effectively useless?
Thanks as ever.
http://developers.facebook.com/blog/post/475
I hate to break form and answer my own question, but from the comments enough people seem to be having this problem.
Digging through the developer updates today I finally found the above post (having already written workarounds, of course) Quoted:
We have removed the ability to turn
user accounts in test accounts as
mentioned here to prevent
unintentional conversions of real
accounts into test accounts. The
proper way to create test accounts is
by using the accounts connection of
App Graph Object.
This tiny notification was mixed in with the updates for March. Probably should RSS their developer blog so these things don't take me by suprise again! This particular update became effective March 4th. In any event, it's good to have a conclusive answer right from the source.
So I simply want to add my current facebook status to my personal website. I have been looking at tutorials and other posts about fb and fb connect, but I am still confused.
Is there anyway to do this with simple REST calls? Like twitter or flickr?
From what I understand I dont need FB connect because I am just getting my own status and do not need to get any info from other visitors.
Any know how to do this?
Facebook does have an API, but unfortunately, you cannot use it without acquiring a secret key. Because Facebook gives users control over their data privacy settings, there is no "public access" to data retrieval methods. You must have a key in order to start fetching things.
All facebook applications are given a secret key when they are created. Users can prevent applications from retrieving their data if they want, hence the need for an associated key.
Facebook Connect applications function in the same way... they are assigned a key that is used remotely from a third-party site (ie. yours).
Unfortunately, without one of those keys you won't be able to access any data, even your own. You could probably come up with a work-around by making your own application and using that key to fetch data on yourself, but you'll need to go through some hoops to make it work on a permanent basis (ie. without a new session each time), like granting the offline_access extended permission.
Facebook Connect
I have spent a few weeks putting together a basic web site which uses Facebook connect as authentication.
I have studied 'theRunAround', the provided example application. However the code is convoluted and uses a large number of files and classes, most of which have a lot of functionality that I have no need for. I have also had a good read of the documentation.
My code works almost all the time. However, occasionally I receive strange, unpredictable errors.
Required Features
Check if user is already logged in to Facebook, if so, retrieve the fb_uid, name, profile pic
Return a list of friends which have also connected to this application
Are there any tutorials, better than the ones provided by Facebook regarding such simple functionality?
I wrote my own library to work with Facebook Connect as I found the one provided to be very lacking.
I can't provide the code as it is company code, but here's a breakdown of what I needed to do. Hopefully you can use it and fill in the blanks easily yourself.
In your application settings, configure the "Connect" tab. The "Connect URL" in my case is the root folder where my xd_receiver.htm file is. Also, under "Advanced" I marked my app as a Web Application.
Put your xd_receiver.htm file in the root folder specified above. There is a ton of documentation on xd_receiver.htm out there. This is what facebook hits when the user logs in. It will write cookies to their browser which your application can read in later to do authentication.
The cookies Facebook sets are in the format of _ where APIKEY is your apps API key and is the name of the cookie. You'll need the _session_key cookie to make further API calls. If this cookie is not set, you need to show the login button as desscribed in steps 4 - 6. Otherwise skip to step 7.
You need to load in the Facebook javascript file on your page that you will have the FB login button. ==> http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php
To show the FB login button, use:
The Facebook JS will automatically render a facebook login button for you. It will trigger the "facebook_onlogin" method that you shall define once the user is logged in so you can do something after they login.
Right below the above markup, you need to call the FB init javascript to have it render the button:
FB.init('YOUR API KEY HERE', 'ABSOLUTE PATH TO YOUR XD_RECEIVER.HTM FILE HERE');
Use the session_key as set in the cookie to make any API calls. How to make API calls is well documented.
Hope this helps.
I have recently added a friend notification feature to Cogenuity using the facebook connect technology.
First, you need to create the facebook object in your php code. I am assuming that you have already done the facebook application registration goodness. I found a lot of the parts to facebook connect not to work but what did work was this.
$user = $facebook->require_login();
I found that the FQL parts worked pretty good.
$query = "select uid1 from friend where uid2 = {$user}";
$results = $facebook->api_client->fql_query($query);
I used this FQL query which may serve your needs.
$query = "SELECT name, pic_square, status, about_me FROM user WHERE uid = {$uid}";
$results = $facebook->api_client->fql_query($query);
As does the notification_send method.
$facebook->api_client->notifications_send($notifyTarget, $intro, 'user_to_user');
I hope this helps.