Call function after oauth success - facebook

How can I call a function, when Facebook has been authourized??
FB.ui({
client_id: '9999999999999',
method: 'oauth',
scope: 'email, user_about_me, user_likes',
response_type: 'token'
});
???

FB.Ui has a callback function.
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);

Facebook state that you should not use the OAuth Dialog directly from the Javascript SDK so here's an example using FB.Login with a callback for when the user has accepted/denied the permissions.
FB.login(function(response)
{
if (response.authResponse)
{
// user has granted permissions
}
else
{
// user did not grant permissions
}
},
{
scope: 'email, user_about_me, user_likes'
}
);

Related

Publishing on users time line using facebook javascript sdk

I have been using Graph API along with javascript facebook sdk to make posts on users wall. The code looks like this
function graphStreamPublish(){
showLoader(true);
FB.api('/me/feed', 'post',
{
message : "Sample Message",
link : 'link url',
picture : 'image url',
name : 'app name',
description : 'Test stuff'
},
function(response) {
showLoader(false);
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
Can this piece of code be used to post on users timeline as well or is there something else I need to do?
The following code works. ( Notice the 'publish_actions' permission used at the end).
FB.login(function(response) {
// handle the response
if (response.status === 'connected') {// Logged into your app and Facebook.
FB.api('/me/feed', 'post',
{
message : "Sample Message",
name : 'app name',
description : 'Test stuff'
},
function(response) {
if (!response || response.error) {
alert(response.error);
} else {
alert('Post ID: ' + response.id);
}
});
}
}, {scope: 'public_profile,email,publish_actions'} );
Years ago, you could use field TO with user id, nowadays you cant post to users timeline, but you can use TO field with an ID, for posting on groups, events or pages .

how post feed entry with publish restriction?

FB.ui({ method: 'feed',
name: name,
link: 'http://apps.facebook.com/my-app/',
picture: 'app-picture',
caption: 'this is only for me',
privacy: { value: 'SELF' }},
function(response) {
if (response && response.post_id) {
// Post was published
alert('Post was published.');
} else {
alert('Post was not published.');
}
return true;
}
);
not working
resolved:
FB.api('/me/feed', 'post', {
message: 'message',
name: 'name test',
caption: 'caption',
privacy: { 'value':'CUSTOM','friends':'SELF'} },
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});

Delete facebook comment from my site or facebook Javascript SDK

I am using facebook javascript SDK to post comment on facebook and using this code:
FB.init({
//appId: 'YOUR_APP_ID', cookie: true,
appId: '2697XXXXXXXXXX098', cookie: true,
status: true, xfbml: true
});
FB.ui({
method: 'feed',
name: 'MyComment',
link: 'http://www.facebook.com./',
picture: 'http://xyz.com/App_Shared/Images/logo.jpg',
caption: 'Comment caption',
description: 'comment description',
message: 'Join facebook.'
}, function (response) {
if (response && response.post_id) {
alert('Post was published.' + response.post_id);
} else {
alert('Post was not published.');
}
});
and now i want to delete this post by using the same type of js code.
I saved post_id in my database.
Can you provide me the code or any URL to do this.....
First of all you must give to access to you application and allow by user according to this URL
http://developers.facebook.com/docs/reference/api/permissions/
These permission you can use like this method
FB.login(function (response) {
if (response.authResponse) {
FB.api('/me', function (response) {
jQuery('#hdfUID1').val(response.id);
jQuery('#btnFBLoginTemp').click();
// FB.logout(function (response) {
// });
});
} else {
jQuery('#hdfUID1').val('');
}
}, { scope: 'email,user_photos,read_stream,publish_stream,offline_access' });
if user allow these permissions then you can delete comment from user's wall which was posted by your application by using "Anatoly Lubarsky" answer method....
FB.api(postId, 'delete', function(response) {
// callback here
});
should be very simple like:
FB.api(postId, 'delete', function(response) {
// callback here
});
hope this helps

Post image to user wall via FB Api

Hi i am trying to post image to friends wall from my FB app. I have this code, but dont know how to attach image to the post. It only posts text. Anybody has working example ? Or where i have error ? thanks.
FULL PATH TO IMAGE HERE - replaced with path to image
FULL PATH TO MY FB APP HERE - replace with path to fb app.
FB.ui(
{
target_id: '100000505490012',
method: 'stream.publish',
message: 'Just Testing!!!.',
attachment: {
name: 'test name',
caption: 'Caption here.',
description: (
'description here'
),
href: 'http://facebook.com/mysite'
},
media: {
type: 'image',
src: 'FULL PATH TO IMAGE HERE',
href:'FULL PATH TO MY FB APP HERE'
},
action_links: [
{ text: 'Code', href: 'FULL PATH TO MY FB APP HERE' }
],
user_prompt_message: 'Personal message here'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
The media attribute actually goes inside the attachment attribute.
FB.ui({
target_id: '100000505490012',
method: 'stream.publish',
message: 'Just Testing!!!.',
attachment: {
name: 'test name',
caption: 'Caption here.',
description: 'description here',
href: 'http://facebook.com/mysite',
media: [{ 'type': 'image', 'src': 'FULL PATH TO IMAGE HERE', 'href':'FULL PATH TO MY FB APP HERE'}]
},
action_links: [{ text: 'Code', href: 'FULL PATH TO MY FB APP HERE' }],
user_prompt_message: 'Personal message here'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);

Setting Facebook Publish Stream URLs

I am using facebook publishStream method in Facebook FBML Application, some other developer worked on it before me. I am using it some thing like this
Facebook.streamPublish('Publish Shirt Tale. <?php echo $canvasURL.'?req=tale-details&tale_id='.$tale_id?>', attachment);
But there is another url that is under the shared image, see below image for more info
So as in image there is encircle link, so that points towards some other page while I want it to the first page of app. It currently goes to a page some thing like this: http://apps.facebook.com/apps/application.php?id=xxxxxxxxxxxxx
so can any one tell that where can I specify that URL?
Thanks in advance
As per facebook is deprecating all FBML apps soon, I would advise you to look here, and try and create a dialog in this way. I can give you the script I'm currently using, where the link you circled directs to my app's home page. a note should be made- my app is an Iframe app.
<script type="text/javascript">
FB.ui(
{
method: 'stream.publish',
attachment: {
name: 'name',
caption: 'caption',
source: 'picture.jpg',
picture: 'picture.jpg',
description: 'description',
href: 'http://apps.facebook.com/appname'
},
action_links: [
{ text: 'name', href: 'http://apps.facebook.com/appname' }
]
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
</script>
If you however you would like to keep your app in the FBML form, try this code:
<script type="text/javascript">
FB.ui(
{
method: 'stream.publish',
attachment: {
name: 'name',
caption: 'caption',
source: 'picture.jpg',
picture: 'picture.jpg',
description: 'description',
href: 'http://apps.facebook.com/appname/index.php'
},
action_links: [
{ text: 'name', href: 'http://apps.facebook.com/appname/index.php' }
]
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
</script>
You need to understand the difference between Iframe and FBML apps: While Iframe apps make the user stay in the same page all the time, and only the content in the Iframe is changes, FBML application actually move the user from page to page. Because of this, when specifying links in FBML apps, it is important to use the http://apps.facebook.com/appname/page link instead of the http://www.yoursite.com/page link.
Example links:
A link on your site: http://www.yoursite.com/game1.php
Would look like this in an FBML app: http://apps.facebook.com/appname/game1.php
ok Hafiz then try this code.
FB.ui({
method: 'stream.publish',
message:'hello',
attachment: {
name: title,
caption: "I'm running!",
media: [{
type: 'image',
href: 'http://www.yoursite.com/',
src: 'http://www.yoursite.com/images/working.jpeg'
}]
},
action_links: [{
text: 'Get your percentage',
href: 'http://www.yoursite/'
}],
user_message_prompt: 'Tell your friends about Get your percentage:'
});