Reputation: 591
I am trying to add a tab to a page, facebooks graph api states a request with the following params should be made:
/PAGE_ID/tabs?app_id=MY_APP_ID&method=post&access_token=PAGE_ACCESS_TOKEN
When i use it with FB.api:
FB.api("/PAGE_ID/tabs?app_id=MY_APP_ID&method=post&access_token=PAGE_ACCESS_TOKEN", function(response) {
});
Response is just a list of tabs on the page, yet when i go to the brwoser and enter the same thing:
https://graph.facebook.com/PAGE_ID/tabs?app_id=MY_APP_ID&method=post&access_token=PAGE_ACCESS_TOKEN
Same request only manually it returns true and adds a tab.
NOTE: I have page access token and a page id as instructed here, sub section "Create".
Upvotes: 0
Views: 256
Reputation: 96407
Response is just a list of tabs on the page
That’s what you get for a GET request to /pageid/tabs
.
So this indicates that your parameter method=post
is not recognized correctly, therefor no POST but just a GET request is made … and you get the list of tabs of the page.
Use this instead, then it should work:
FB.api("/PAGE_ID/tabs?app_id=MY_APP_ID&access_token=PAGE_ACCESS_TOKEN",
"post",
function(response) { console.log(response); }
);
Telling FB.api what method to use is done here via the second parameter, by just passing the method name as a string, "post"
.
Just tested this using a page and app of mine – it just returns true
in the console as expected, and the app is installed as page tab app on the page afterwards.
Upvotes: 1
Reputation: 6138
Can you try out this code:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<title>My Add to Page Dialog Page</title>
</head>
<body>
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<p><a onclick='addToPage(); return false;'>Add to Page</a></p>
<p id='msg'></p>
<script>
FB.init({appId: "YOUR_APP_ID", status: true, cookie: true});
function addToPage() {
// calling the API ...
var obj = {
method: 'pagetab',
redirect_uri: 'REDIRECT_URI',
};
FB.ui(obj);
}
</script>
</body>
</html>
Upvotes: 0