Facebook graph api adding custom tab not working - facebook

I'm trying to add custom tab using facebook graph api. I tried everything on the doc but nothing is working. Here's my sample code.
$('#addTab').click(function(event){
FB.ui({
method: 'pagetab',
redirect_uri: 'https://{mydomain}.com',
}, function(response) {
if((response && !response.error_code) || window.mobileAndTabletCheck()) {
console.log(response);
FB.api(
'/{mypageid}/tabs',
'POST',
{"custom_name":"My Custom Tab","tab":"app_{myappid}",
"access_token":"{I put my access token here}"},
function(response) {
// Insert your code here
//
}
);
} else {
console.log('error');
}
});
});
But I'm getting this messages from the two method
FB.ui
FB.api

Related

Facebook Graph API - Adding tab

I am trying to add a tab trought the facebook js api, and it fails:
Login with permissions:
FB.login(function(response) {
console.log(response);
}, {
scope: 'publish_actions, manage_pages'
});
FB.login(function(response) {console.log(response);
}, {perms:'read_stream,publish_stream,offline_access'});
reading pages to get token:
FB.api(
"/me/accounts",
function (response) {
if (response && !response.error) {
console.log(response)
}
}
);
adding a tab, for example, these two methods:
a.
FB.api(
"/{page_id}/tabs/",
"POST",
{
"app_id": "{app_id}",
access_token: "{token}"
},
function (response) {
console.log(response)
}
);
I get response:
Object {success: true}
b. tried directly:
jimdoGen002.getJSON('https://graph.facebook.com/{page_id}/tabs?app_id={app_id}&access_token=token&callback=?', function(r){console.log(r)})
I get response, array with the tabs the user page has, but without my new tab.
going to the user page - no new tab.
My questions:
what am I missing? why do I get sucess but cant get the tab?
if its because the review of "manage_pages" by facebook is not complete yet - why do I get success?
if the above - how can I test manage pages BEFORE I post it to facebook review?
Can I add a tab WITHOUT an app inside? just an iframe url?
Thanks in advance,
Lior.
(to make it all simple:)
FB.api(
"/me/accounts",
function (response) {
var token = response.data[0].access_token;
var id = response.data[0].id;
console.log(response.data[0].name);
FB.api(
id + '/tabs',
"POST",
{
"app_id": {app_id},
"access_token": token
},
function (response) {
console.log(response);
FB.api(
id + '/tabs/{app_id}',
function (response) {
console.log(response)
},
{
access_token: token
},
function(response) {
console.log(response)
}
);
}
);
}
);
result:
my page
Object {success: true}
Object {data: Array[2]} - none is my app.

Facebook Post through Graph API with access token

I am developing a facebook app where I need impersonation of users, so there is an option when you use facebook for "Use Facebook As", i need to implement the same in my app.
I see the access tokens retrieved for the pages I own, but I don't understand how to use this with the following graph api to post
var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function (response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
so my question is how do I set the access token for the api in this case??
I Hope, am clear with my question
Add it with the parameters. Change this line
FB.api('/me/feed', 'post', { message: body }, function (response) {
to...
var my_token = "the access token value";
FB.api('/me/feed', 'post', { message: body, access_token : my_token }, function (response) {

Facebook API feed dialog - prevent unnecessary click

hi,
Using Facebook's API it's possible to prompt a user to post to his/her wall using the feed dialog. However, using the javascript SDK, this requires two clicks: one on the button which brings up the dialog, the other on the "Share" button within the dialog.
Is it possible to get rid of one of these clicks? I thought of two approaches:
Embedding the dialog within an iframe, as Facebook provides a URL for a full page dialog. That will require the user to click only on the "Share" button. Apparently Facebook blocks that option.
Using an access token and display=iframe, but I want to avoid the user having to authorize my application.
Any ideas?
i would suggest you to use fb.api instead.
function PostToMyWall(){
FB.login(function(response)
{
if (response.authResponse)
{
//Post to my wall
FB.api('/me/feed', 'post', {
message: lnk,link: lnk
},
function(response) {
if (!response || response.error) {
// //alert('Error occured');
} else {
// //alert("Successfully Posted to My Wall!");
}
});}else
{
alert('Not logged in');
}}, { scope : 'publish_stream' });
}
My application got a similar function, check it out at www.wootube.woolei.com - "Post to WooTube Page and Group"
or popup when the page using jquery
$(document).ready(function() { FB.ui({method: 'feed',
name: mdtxt,
link: lnk,
picture: hackImageUrl(img,fld),
caption: '<?php echo $clickme; ?>',
description: '<?php echo $app_desc; ?>'
},
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert("Successfully Posted to Group");
}
});});

Is there a way to post a message to a Facebook group's feed?

I'm working on a Facebook app that uses Facebook groups, and I'd like to open up a Feed dialog to let the user post a notice to the group's feed. I have a user who is in the group and I've got the relevant permissions as well.
I've tried passing the group's Facebook id in the https://developers.facebook.com/docs/reference/dialogs/feed/ feed dialog, but get a Facebook error. There doesn't appear to be a programmatic way to do it either: the group's feed (described at https://developers.facebook.com/docs/reference/api/group/) isn't documented to accept POSTs either. Is there a way to post a message to the group using the Graph API or one of the other API methods?
I just made a test and it's working as any other wall.
I made a POST to 'GROUP_ID/feed' with a message variable with a value and it worked. I logged into the app as the group owner.
Using facebook php-sdk:
$facebook->api('GROUP_ID/feed', 'POST', array(
'message' => 'Testing...'
)));
I would suggest to use javascript instead as it wont cause post back of our website.
Check out my application to see if that what you want -> WooTube
function Promote() {
var lnk =
'http://www.wootube.woolei.com?v=<?php echo $_GET["id"] ?>';
FB.login(function(response) {
if (response.authResponse) {
//Post To WooTube Group
FB.api('/271691796276524/feed', 'post', {
message: lnk,
link: lnk,
},
function(response) {
if (!response || response.error) {
//alert('You have to join the group first!');
} else {
//alert("Successfully Posted to WooTube Group!");
}
});
//Post to Wootube Page
FB.api('/173724382762792/feed', 'post', {
message: lnk,
link: lnk
},
function(response) {
if (!response || response.error) {
//alert('You have to like http://www.facebook.com/WooTubes first!');
} else {
//alert("Successfully Posted to WooTube Page!");
}
});
} else {
alert('Not logged in');
}
}, {
scope: 'publish_stream'
});
}

Publish to Current user's wall using FBJS in FBML application

I need to publish some message to the current user's wall using FBJS in FBML application.
When I use
window.fbAsyncInit = function() {
FB.init({appId: 'MY_APP_ID', status: true, cookie: true, xfbml: false});
};
i am getting an error :- FB is not defined.
and
window is not defined.
For publishing i am using this code
function graphStreamPublish(){
var body = document.getElementById("txtTextToPublish").value;
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
// alert('Error occured');
} else {
// alert('Post ID: ' + response.id);
}
});
}
(I cannot use alert in facebook..)
Thanks in advance..
If you're using FBML, you should be using FBJS instead of the Facebook Connect API.
var body = document.getElementById('txtTextToPublish').getValue();
Facebook.streamPublish(body);
Note the getValue() call instead of .value due to use of FBJS.