How to use the user object in Facebook dialog using Facebook javascript SDK? - facebook

I want have feed dialog in which i also want to use his First name or user object.I'm using FB.Ui method.
<script>
var publish = {
method: 'stream.publish',
display: 'popup', // force popup mode
attachment: {
name: 'I visted this Appp',
caption: 'The Facebook Connect JavaScript SDK',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
href: 'http://fbrell.com/'
}
};
FB.ui(publish, Log.info.bind('stream.publish callback'));
</script>
As you can see in caption it is ' i visited this app'.I want to change it to the Facebook user's first name..i.e 'first_name visted this app'..Anyone can help me out

To get info about the user, you would first need to have them authenticate with your application (no extended permissions would be needed as name is considered "basic" information). Then you could then call a FQL query with the javascript api to get their name and then use that to populate the message.
Authenticate user:
<fb:login-button autologoutlink="true"></fb:login-button>
Get users name:
FB.api(
{
method: 'fql.query',
query: 'SELECT name FROM user WHERE uid='+FB.getSession().uid
},
function(response) {
alert(response[0].name);
}
);

Related

facebook api with private message multiple to (friends)

I development facebook private message for invite with facebook api.
<script>
FB.init({ appId: 'xxxxxxxxxx', xfbml: true, cookie: true });
FB.ui({
method: 'send',
to: ['1736383768','590528674'],
// picture: 'http://thinkdiff.net/iphone/lucky7_ios.jpg',
//Can be page, popup, iframe, or touch.
display: 'popup',
name: 'yyyyyy',
link: '<%=Request.QueryString["link"]%>'
});
</script>
but adds only the first mate.
how to multiple friends send private message ?
var publish =
{
method: 'stream.publish',
message: 'Some kind of test',
uid: uid,
attachment: {
name: 'Test',
caption: 'Facebook API Test',
description: ('Sure hope it worked!'),
href: 'http://www.test.com/',
media: [
{
type: 'image',
href: 'http://test.com/',
src: 'http://test.com/image.jpg'
}
]
},
action_links: [
{ text: 'Your text', href: 'http://www.test.com/' }
],
user_prompt_message: 'Share your thoughts about test'
};
publish.target_id = friendID;
FB.ui(publish);
publish.target_id = friendID;
FB.ui(publish);
return false;
You should not use stream.publish.
As said by facebook : "We are in the process of deprecating the REST API, so if you are building a new application you shouldn't use this function. Instead use the Graph API and POST a Post object to the feed connection of the User object"
So, now you have the send and feed methods left.
You cannot fill the send method with more than one user id (you can only if you are whitelisted by facebook, but I'm not quite sur how to do this , I would not count on it either).
You can use the feed method to post on many user's friends wall with something like this
FB.api('/USERID/feed', 'post', {
name:postName,
link:postLink,
picture:postPicture,
description:postDescription,
message:postMessage
}, function (postResponse) { //DO SOMETHING HERE });
But doing it, you are taking the risk of your app being deleted by facebook if someone flag it as spam.
As far as I know, sending messages to multiple friends via an App is considered bad/spam by facebook so they do not allow this anymore.
You still can Invite as many friends as you want via the App request dialog (method apprequests) but I'm not sure this is what you want.

FB.ui is giving me Error Message: redirect_uri is not owned by the application

Help please! I'm creating a Facebook tab/app on facebook for a contest, part of the contest is to have a user have the option to share the contest on their wall. This is the error I'm receiving -
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: redirect_uri is not owned by the application.
This is my facebook auth code:
<div id='fb-root'></div>
<script>
FB.init( {
appId : 219691398094935,
status : true,
cookie : true,
xfbml : true
}
);
window.fbAsyncInit = function() {
FB.Canvas.setAutoResize();
}
</script>
<script src='http://connect.facebook.net/en_US/all.js'></script>
This is my FB.ui Code:
<script>
function showStreamPublish() {
FB.ui(
{
method: 'feed',
name: 'I signed up to win an iPad 2 from Upillar.com',
link: 'http://www.facebook.com/pages/udev/121216321302968?sk=app_219691398094935',
picture: 'http://static.upillar.com/fb/images/logo.png',
description: 'I entered the iPad 2 Sweepstakes from Upillar.com which only requires you to create a listing to enter! Enter the contest now by by clicking this link.',
app_id: '219691398094935'
},
function(response) {
if (response && response.post_id) {
$('#main-screen').css('display','none');
$('#step2').css('display','block');
}else{
$('#main-screen').css('display','none');
$('#step2').css('display','block');
}
});}
</script>
This is the information in my app:
Site/App Domain: upillar.com
Site URL: http://fb.upillar.com/contest.php
Page Tab URL: http://fb.upillar.com/contest.php
Secure Tab URL: https://fb.upillar.com/contest.php
Please tell me what am I missing! Thank you so much.
Got same problem - solution is simple, but not even mentioned by Facebook Dev DOCS. Take a look at this:
FB.ui(
{
method: 'feed',
redirect_uri: 'http://www.yourdomain.com', // that caused the problem
message: 'getting educated about Facebook Connect',
name: 'Connect',
caption: 'The Facebook Connect JavaScript SDK',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
link: 'http://www.yourdomain.com',
picture: 'http://www.yourdomain.com/f8.jpg',
actions: [{
name: 'yourdomain',
link: 'http://www.yourdomain.com'
}],
user_message_prompt: 'Share your thoughts about RELL'
},
function (response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
site URL should not be a file, try to set this as your domain only, without contest.php
if that does not work, set the canvas URL as your domain, with "/" at the end too.
Sorry to bump an old post, first I should say i'm relatively new to facebook development but i've been getting the same problem, basically it seems like facebook does some fairly nifty detection in terms of what qualifies as a redirect when you land on your page.
For example I was detecting if it was a new user and then displaying a colorbox, whose onclick event redirected to a newuser creation form. That gave me error 191 redirect_uri not owned. It seems because the javascript was in the <HEAD> element it qualified as a redirect.
I simply changed the login process to fully render the main page and display a normal div telling them to click here to login.
Sorry for grave-digging!
I just had the same problem and found the solution. You do not have to change anything on your sources.
Just head over to http://developers.facebook.com open your app and navigate to "Settings" and "Basic".
There is a textfield that says "App Domains" - enter the domain name where the app is currently hosted at there, save the settings and you are done.

action links text in facebook post to wall dialog using javascript not working

I trying to bulid a facebook application using javascript.In my application, the user gets the result and a dialog after a time delay popup. Everthing is working well except one here's my code for the 'post to wall dialog'
<script>
var publish = {
method: 'stream.publish',
display: 'popup', // force popup mode
attachment: {
name: 'Connect',
caption: 'The Facebook Connect JavaScript SDK',
actions: [{ name: 'action_links text!', link: 'http://www.example.com' }],
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
href: 'http://www.example.com/'
}
};
FB.ui(publish, Log.info.bind('stream.publish callback'));
</script>
The line containing actions not working for me.Can anyone just inform what is the solution for this...
The property should be called action_links not actions and only have text and href values. Use something like:
action_links: [{ text: 'action link test', href: 'http://example.com'}]
Note that the action must be defined through the fb web interface for the app!

facebook stream.publish

I'm making a facebook app and using stream.publish to share something on a wall.
However for the 1) attachemnt link, and the 2) the FB UI action link, when I click either, it will load the page in the same browser window.
I would like to somehow add into these links something like target="_blank" so it opens the link in a new tab.
I know this is possible because when I share a video on youtube it has a target="_blank" on the action link and on the share link.
Does anyone know the trick?
I've tried code like this (I inserted the target blanks) but it doesn't add a target element in the hyperlinks:
FB.ui(
{
method: 'stream.publish',
message: 'Check out this great app! http://apps.facebook.com/{your_app}',
attachment:
{
name: 'Connect',
caption: 'The Facebook Connect JavaScript SDK',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'),
'media': [{
'type': 'image',
'target': '_blank',
'src': 'http://test3.com/test.png',
'href': 'http://test3.com'}],
href: 'http://test2.com',
target: '_blank'
},
action_links: [
{ text: 'Code', href: 'http://github.com/facebook/connect-js' }
],
user_message_prompt: 'Share your thoughts about Connect',
target: '_blank'
}
);
Does anyone have any idea how youtube can accomplish the targets
I believe what you are looking for is
display: 'popup', after method: 'stream.publish'
target is in reference to a fb user_id to post a wall-to-wall

How can I paste img tag into stream.publish method?

I am new in Facebook API, I found only that page about fb.ui http://developers.facebook.com/docs/reference/javascript/FB.ui . I use new connect-js, and when i just place in my text <img src="/sa/asd/asd.jpg" /> slash is escaping to \/.
Please help!
You need to set media property of attachment object, something like:
attachment: {
name: 'Connect',
caption: 'The Facebook Connect JavaScript SDK',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
media: [{
type: 'image',
src: 'http://example.com/img.jpg',
href: 'http://example.com'
}],
href: 'http://github.com/facebook/connect-js'
},
You can read more about attachments here.