vendredi 27 février 2015

NodeJS Facebook User Feed Subscriptions: Invalid OAuth access token

Am close to tearing my hair out (as a passionate developer, should), so hopefully I can get some help on this one. After reading a bunch of forums and sifting through facebook documentation, here is a log file of trying to make a subscription to user feed's. I really only need to know if the bottom set of API's I am running should work in theory. Here is my log:



*********************************************************
makeRequest - Host: graph.facebook.com - Path: /v2.2/{ app_id }/subscriptions?object=user
*********************************************************
Type: DELETE
*********************************************************
Wed Feb 25 2015 12:52:15 GMT+0000 (UTC) Server is listening on port 81
*********************************************************
makeRequest - Host: graph.facebook.com - Path: /oauth/access_token?client_id={ app_id }&client_secret={ app_secret }&grant_type=client_credentials
*********************************************************
Type: GET
*********************************************************
App Access Token: { app_token }
*********************************************************
makeRequest - Host: graph.facebook.com - Path: /v2.2/{ app_id }/subscriptions?&object=user&fields=feed&callback_url={ uri_encoded_ callback_url }&verify_token={ verify_token }&access_token={ app_token }
*********************************************************
Type: POST
*********************************************************
Success: {"error":{"message":"Invalid OAuth access token.","type":"OAuthException","code":190}}


So here I am first trying to delete any subscriptions currently active, then using the API to get issued a new application access token, and finally to make a new subscription. Here is my function to initialize this whole process:



function subscribe_facebook(http,https) {
var oauth_obj = getOauthObj('facebook');

// First Delete
var url = oauth_obj.subscription_url;
var host = splitUrl(url,"host");
var path = splitUrl(url,"path");

path += "?object=user";

makeRequest(http,host,path,80,'DELETE',function(ret){
// Get App Access Token
url = oauth_obj.access_token_url;
host = splitUrl(url,"host");
path = splitUrl(url,"path");

path += "?client_id=" + oauth_obj.app_id;
path += "&client_secret=" + oauth_obj.app_secret;
path += "&grant_type=client_credentials";

makeRequest(https,host,path,443,'GET',function(ret){
facebook_app_token = ret.toString().split('|');
facebook_app_token = facebook_app_token[1];
consoleLogger("App Access Token: " + facebook_app_token);

subscribe(https,'facebook',443,'POST',facebook_app_token,myServer);
});
});
}


And here is the subscribe function it enters:



function subscribe(http,type,port,method,access_token,myServer) {
var oauth_obj = getOauthObj(type);
var sub_post_data = "";
switch (type) {
case "facebook":
sub_post_data =
"&object=" + "user"+
"&fields=" + "feed"+
"&callback_url=" + encodeURIComponent(myServer + "/" + type) +
"&verify_token=" + "*****" +
"&access_token=" + access_token
break;
}

var host = splitUrl(oauth_obj.subscription_url,"host");
var path = splitUrl(oauth_obj.subscription_url,"path");
path += "?" + sub_post_data;

makeRequest(http,host,path,port,method,function(ret) {
consoleLogger("Success: " + ret);
});
}


Being that the OAuth is invalid, I'm assuming that I'm not passing the right parameters to the oauth API to do this or not - can someone steer me in the right direction?


Aucun commentaire:

Enregistrer un commentaire