Sunday, 15 July 2012

ruby on rails - Koala gem and getting album photos from friends -



ruby on rails - Koala gem and getting album photos from friends -

i creating facebook application. signing in user omniauth-facebook gem. asking next permissions:

provider :facebook, 'app_id', 'secret_key', scope: "public_profile,user_friends,friends_photos,user_photos"

after user signs in, getting friends' list koala gem , next code:

@graph = koala::facebook::api.new(current_user.oauth_token) @profile = @graph.get_object("me") @friends = @graph.get_connections("me", "friends?fields=id,name,gender")

i don't know if can albums , photos each 1 of friends. i've tried next fql query:

select pid photo aid in (select aid,name album owner=user_id)

which works me when testing on graph api explorer, doesn't work application (neither friends nor me).

am missing permissions or impossible photos , albums of someone's friends? other suggestion getting photos of someone's friends through facebook graph api?

update

i've uploaded code here https://github.com/johndel/fbgame can see above code , rest of on config/initializers/omniauth.rb , on app/controllers/pages_controller.rb

the problem has permissions app asking during sign up. if check it, doesn't inquire friend's photos.

the above means problem has omniauth-facebook gem using. using old version of (version 1.4.0), though updated , still didn't work current version (1.6.0).

i made work javascript version generating right omniauth key , asking preferable permissions (friend's photos access). after sign in, worked nicely koala gem, have omniauth key through other method, current omniauth-facebook gem seems have bug (i think javascript method i've used, suggested way it).

here code javascript (most of copy-paste facebook graph api):

<!doctype html> <html> <head> <title>facebook login javascript example</title> <meta charset="utf-8"> </head> <body> <div style="width: 900px; margin: 0 auto;"> <script> // called results from fb.getloginstatus(). function statuschangecallback(response) { // response object returned status field lets // app know current login status of person. // total docs on response object can found in documentation // fb.getloginstatus(). if (response.status === 'connected') { // logged app , facebook. testapi(); } else if (response.status === 'not_authorized') { // person logged facebook, not app. document.getelementbyid('status').innerhtml = 'please log ' + 'into app.'; } else { // person not logged facebook, we're not sure if // logged app or not. document.getelementbyid('status').innerhtml = 'please log ' + 'into facebook.'; } } // function called when finishes login // button. see onlogin handler attached in sample // code below. function checkloginstate() { fb.getloginstatus(function(response) { statuschangecallback(response); }); } window.fbasyncinit = function() { fb.init({ appid : 'api_key', cookie : true, // enable cookies allow server access // session xfbml : true, // parse social plugins on page version : 'v2.0' // utilize version 2.0 }); // we've initialized javascript sdk, phone call // fb.getloginstatus(). function gets state of // person visiting page , can homecoming 1 of 3 states // callback provide. can be: // // 1. logged app ('connected') // 2. logged facebook, not app ('not_authorized') // 3. not logged facebook , can't tell if logged // app or not. // // these 3 cases handled in callback function. fb.getloginstatus(function(response) { statuschangecallback(response); }); }; // load sdk asynchronously (function(d, s, id) { var js, fjs = d.getelementsbytagname(s)[0]; if (d.getelementbyid(id)) return; js = d.createelement(s); js.id = id; js.src = "//connect.facebook.net/en_us/sdk.js"; fjs.parentnode.insertbefore(js, fjs); }(document, 'script', 'facebook-jssdk')); // here run simple test of graph api after login // successful. see statuschangecallback() when phone call made. function testapi() { fb.api('/me/albums', function(response) { console.log(json.stringify(response)); // document.getelementbyid('status').innerhtml = // 'thanks logging in, ' + response.name + '!'; }); } </script> <!-- below include login button social plugin. button uses javascript sdk nowadays graphical login button triggers fb.login() function when clicked. --> <fb:login-button scope="public_profile,user_friends,friends_photos,user_photos" onlogin="checkloginstate();"> </fb:login-button> <div id="fb-root"> </div> <div id="status"> </div> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script> $(function() { // fb.api('/me', function(response) { // console.log(json.stringify(response)); // }); }); </script> </div> </body> </html>

after successful generated omniauth key right permissions works. can test koala or javascript way, have done calling above method.

ruby-on-rails facebook-graph-api facebook-fql omniauth koala

No comments:

Post a Comment