p5-Facebook-OpenGraph icon indicating copy to clipboard operation
p5-Facebook-OpenGraph copied to clipboard

Updates to documentation - partly to reflect FB API changes

Open saturdaywalkers opened this issue 7 years ago • 2 comments

Hi Thanks for the module! Some documentation changes.

  1. FQL is no more
  2. Current version is 2.8, One of the changes is you can't call by "alias", you need to call by "id"
  3. You now need an access token for everything.
  4. You only get data back that you have been explicitly authorised for. Example 1. You have the user_friends scope. You still cannot get a list of all your friends. Only the friends who have also authorised your app with the user_friends scope. Example 2. Someone has shared an album with your page. You cannot get a list of photos in the album unless they have also authorised your app with the user_photos scope 5.. The difference between a server app and a web app wasn't clear. i.e.

A "server" access_token lasts for 60 days. The 60 days is reset every time you use the access_token, i.e. if you keep using it, it never expires.

A "web" access_token lasts for an hour or so. Your web app will need to redirect the user needs to Facebook every session to get a fresh access_token each time. Assuming they've previously authorised your app, Facebook redirects them straight back to you with a new access_token.

This is the work flow for a "sever" access_token.

  1. Create a web page with your app_id, secret and required scopes. This will redirect the user to Facebook. They will have to accept (some of) the scopes, and click OK. This will them redirect them back to your website.

`$fb = Facebook::OpenGraph->new ( app_id => 'your app id', secret => 'your secret', redirect_uri => 'https://your-redirect-url' });

$auth_url = $fb->auth_uri({ scope => [qw/email user_photos user_managed_groups publish_actions user_friends/], }); # see https://developers.facebook.com/docs/facebook-login/permissions

print "Cache-control: no-cache\n"; print "Location: $auth_url\n\n";`

  1. Create a 2nd webpage to receive the redirect. Use the parameter facebook sends you to get a lon lived access_token

`print "Cache-control: no-cache\n"; print "Content-type: text/html\n\n";

$fb = Facebook::OpenGraph->new ( { app_id => 'app id', secret => 'secret', redirect_uri => 'same url as above' });

$cgi = new CGI; $code = $cgi->param('code') ; # read the 'code' parameter in the URL $token_ref = $fb->get_user_token_by_code( $code ); # send code, app id, app secret to facebook to get a long lived access token

print "Access token: $token_ref->{access_token}\n\n"; # save this for future use

$fb->set_access_token( $token_ref->{access_token} ); # now you can use it

$data = $fb->get('me'); use Data::Dumper; print Dumper( $data);`

  1. Now you're good to go with a server-side script. As long as you use the access_token's, they never expire.

`$fb = Facebook::OpenGraph->new ( { app_id => 'app id', secret => 'secret', app_token => 'the one you saved earlier' });

#get my albums, max 10 photos from each album $url = "me/albums?fields=description,from,name,type,updated_time,photos.limit(10)" $data = $fb->get( $url ); use Data::Dumper; print $data `

saturdaywalkers avatar Mar 20 '17 13:03 saturdaywalkers

Thanks for heads-up, @saturdaywalkers.

Since a) this issue includes some sub-issues and b) some sub-issues does not include suggestion/problem for code change, I am going to add replies/questions for each of them with the exact numbering you gave to minimize further confusion.

1. No more FQL support

Right. FQL is no longer supported as of v2.1. and the current oldest version they are supporting is v2.2 -- v2.2 support is going to be removed in couple of days, BTW. So it is safe to say that we can remove FQL support from this module. Is this what you are suggesting?

2. No "alias" support

Since Graph API v2.0, app specific id is dispensed and we can no longer access to object via global id or username. Is this what you are talking about by saying no "alias" support? And I'm not sure what code change or documentation change you are trying to suggest.

3. Access token required for every API call

Yes. So you better specify one.

4. You only get data back that you have been explicitly authorised for.

Yes. Ask user for permissions.

5. Server app v.s. web app.

I am confused what you are trying to ask or suggest. If you are asking about exchanging short-lived access token for long-lived one, the official documentation is provided at Expiration and Extension of Access Tokens, User Access Tokens > Short-Term Tokens and Long-Term Tokens, etc... This module, Facebook::OpenGraph, of course supports this token exchange feature with exchange_token method.

oklahomer avatar Mar 26 '17 03:03 oklahomer

Hi

No code change - just some suggested 'perldoc' documentation updates.

Mainly as Facebook's API has moved on since the last release.

For example,

The perldoc synopsis starts

# fetching public information about given objects my $fb = Facebook::OpenGraph->new; my $user = $fb->fetch('zuck'); my $page = $fb->fetch('oklahomer.docs'); my $objs = $fb->bulk_fetch([qw/zuck oklahomer.docs/]);

There are no more public request, so it would be better to start the synopsis with

  • getting a code, then an access token.
  • then some sample requests.

Change the example requests to use ids, rather than names, something like $fb->fetch( '1234567'); # a user - zuck $fb->ftech('987654'); # a page - the perl foundation $fb->fetch('1234566'); # a photo

Similarly, FQL is being phased out, so maybe mark it as depreciated, or remove it

Cheers, Andrew

saturdaywalkers avatar Mar 27 '17 13:03 saturdaywalkers