Cody Blue
Posts: 0
Joined: Sun Aug 25, 2013 2:11 am

Issue with Facebook API

Thanks Yuri - much appreciated. I should have looked at the implementation bit more carefully.

rodzeus
Posts: 0
Joined: Fri Feb 21, 2014 6:28 pm

Issue with Facebook API

Hi, I am having the same problems. It is logging me into Facebook but if I add the publish_actions to the scope, it is not loading the page at all. What am I doing wrong? Thanks. Here is my code below:

(function(context) {
Helper = {};
var ref;
// var projectId = window.location.href.split("/")[5];

Code: Select all

 Helper.init = function() { 

     var callbackUrl = "[url=http://appery.io/app/view/]http://appery.io/app/view/[/url]" + Facebook_Settings.project_id + "/Login.html?targetPage=Facebook_Me"; 

var url = "https://www.facebook.com/dialog/oauth...=" + Facebook_Settings['client_id'] + "&redirect_uri="

  • encodeURIComponent(callbackUrl) + "&scope=user_hometown,publish_actions&response_type=token";

    Code: Select all

     if (this.isPhoneGapApp()) { 
         ref = window.open(url, '_blank', 'location=yes'); 
         ref.addEventListener("loadstart", this.getAccessToken); 
     } else { 
         window.open(url, "_self"); 
    
     } 

};

Code: Select all

 Helper.getAccessToken = function(event) { 

     if (event.url.indexOf('access_token') = 0) { 
         console.log("Extracting access_token..."); 
         var params = event.url.split("access_token="); 
         var _access_token = params[1].slice(0, params[1].indexOf("&")); 
         localStorage.setItem('access_token', _access_token); 
         ref.close(); 
         Appery.navigateTo('Facebook_Me', {}); 

     } 

 }; 

 Helper.isPhoneGapApp = function() { 
     return (document.URL.indexOf('a href="http://" rel="nofollow"http:///a') === -1 && document.URL.indexOf('a href="https://" rel="nofollow"https:///a') === -1); 
 }; 

 if (window.location.href.indexOf("access_token") != -1) { 
     var hashFromFb = window.location.hash; 
     window.location.hash = ''; 
     var paramsFromFb = hashFromFb.substring(1).split("&"); 
     var access_token = paramsFromFb[0].split("=")[1]; 
     localStorage.setItem('access_token', access_token); 

 } 

 context.Helper = Helper; 

})(window);

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Issue with Facebook API

Hi rodzeus,

It's hard to say what is wrong now,

Please give us your app public link and describe steps to reproduce this problem.

We will take a look.

Regards.

Return to “Issues”