I want to send Facebook friend invitations to some of our friends list without using FBML tags (<fb:request ....)
I am writing code in ASP.NET using fbServices.
How can I send friend requests without using FMBL tags?
Friend requests cannot be done through the Facebook API. The FBML fb:request-form tag is the only way to do this.
I spent a great deal of time looking, and finally came accross a very simple solution.
Using the Facebook Javascript API you can do a friend request with:
<script>
FB.ui(
{
method: 'friends.add',
id: fbid // assuming you set this variable previously...
},
function(param){
console.log(param);
// If they cancel params will show:
// {action:false, ...}
// and if they send the friend request it'll have:
// {action:true, ...}
// and if they closed the pop-up window then:
// param is undefined
}
);
</script>
The callback script can then simply performs an ajax call to your server where
you save info about the action, if needed.
You can test this by using the javascript console app on Facebook:
http://developers.facebook.com/tools/console
Paste in the script above, including the tags, or click the "Examples"
button on the bottom of the text area and find the "fb.ui — friends.add" example.
fb:request-form is now obsolete and will be deprecated eventually. The new way, announced on 27 January 2011, is the Requests Dialog.
Facebook does not allow you to programatically send friend requests.
I suggest taking a look at their API
Okay. Years later, things has changed:
https://developers.facebook.com/docs/reference/dialogs/
Dialogs provide a simple, consistent interface to provide social
functionality to your users. Dialogs do not require any additional
permissions because they require user interaction. Dialogs can be used
by your application in every context: within a Canvas Page, in a Page
Tab, in a website or mobile web app, and within native iOS and native
Android applications.
There are currently 7 Dialogs available for you to use:
- The Feed Dialog allows a user to post a story to their Timeline and to their friends' News Feeds
- The OAuth Dialog allows a user to authorize an application as part of an authentication flow.
- The Add Page Tab Dialog allows a user to add an application to a Facebook Page which they administer.
- The Friends Dialog allows a user to send a friend request to another user.
- The Pay Dialog allows a user to make a purchase using Facebook Credits.
- The Requests Dialog allows a user to send a request to one or more of their friends
- The Send Dialog allows a user to send a Facebook Message to one or more of their friends.
See also: https://developers.facebook.com/docs/requests/
You can send requests to friends without using FBML as follows
`FB.ui({
method: 'apprequests',
message: 'This is my applicaiton',
title: 'Application Request without FBML',
filters: 'all'
},
// Callback function returning the list of requestObj Ids
function(response){
}
);`
For more info you could refer
Wiki Page for apprequest graph API
Related
So, I've created a wedding event on my FB account. Now on my website (static) I would like to have a form (maybe embedded or something from FB) that a visitor could leave a message on it for greetings. That message would instantly post on the event I have created.
I hope you understand what I would like to achieve.
Is it now possible to do that? Or Is there an API for this? comment mirroring seems not applicable for events.
If it's not possible to achieve, is there an alternative that is easy to integrate on my site and of course the message will post on FB.
There are tons of APIs for Facebook, all listed on the Facebook developers documentation page: https://developers.facebook.com/docs/
But I think what you're looking for is something like this:
https://developers.facebook.com/docs/javascript/examples
Trigger a Share dialog
The Share Dialog allows someone using a page to post a link to their timeline, or create an Open Graph story. Dialogs displayed using the JavaScript SDK are automatically formatted for the context in which they are loaded - mobile web, or desktop web.
Let's make an API call to publish a message. Add the code into the response function of the FB.login call you added above:
FB.login(function(){
// Note: The call will only work if you accept the permission request
FB.api('/me/feed', 'post', {message: 'Hello, world!'});
}, {scope: 'publish_actions'});
Try the script. A status message will be posted to your timeline: Hello, world!
I've put a Like Gate on a few of my Facebook Pages and I'm getting a lot of complaints saying that people can't access the content via their mobile device since the mobile version of the facebook website, and the facebook apps for ios/android, don't support tabs on Facebook.
I see there are services out there (I'm not sure how legit they are) that offer a way to create a mobile like gate for your page tab, but I can't find any documentation on how they do it. These services are not suitable for me, because the content on my tab is custom and dynamic.
So, how can I create a interstitial page for a mobile page that requires the visitor to have liked my Page on Facebook before they can proceed? This has to work for new users, as well as existing users who re-visit the tab and without requiring an install to an application.
Thanks!
One approach you can take for a mobile site is to check that the user has liked the page in question via the JS SDK.
If you have a logged-in user to your application, you can Subscribe to the authResponseChange FB event within your JS SDK initialization, or call a function directly to make an API request to verify if the user is a fan of your page.
In your initialization:
FB.init({appId: YOUR_FB_APP_ID_HERE });
window.fbAsyncInit = function() {
// React to a user clicking an on-page Like button:
FB.Event.subscribe("edge.create", verifyUserLikesPage);
}
You can verify that the user likes the appropriate page in the like handler:
function verifyUserLikesPage() {
FB.api("/me/likes/"+FBID_OF_PAGE_TO_ENSURE_THEY_LIKE, function(apiResponse){
if (apiResponse.data && apiResponse.data.length > 0)
// User likes the page. Enabled them to proceed
else
// User does not like the page. Require they click Like.
}
}
More information on the edge.create subscribe via JS available here: https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/
Im trying to put the facebook permissions dialog within an iframe, however not making much progress because of lack of Facebook documentation, and the undocumented hacks around web are not working any more.
news.yahoo.com does something that i would like to emulate.
When you click on a news article it says login with facebook. After the initial oauth dialog to authenticate the user ( which does not ask for permissions), yahoo pop's another dialog from a yahoo URL which included the Permissions dialog within as an IFrame.
Does anybody know what API's can be used to accomplish this?
The fiddler trace indicates that the yahoo URL is calling:
the uiserver.php endpoint with the permissions.request method.
https://www.facebook.com/connect/uiserver.php?method=permissions.request&app_id=194699337231859&display=iframe&redirect_uri=https%3A%2F%2Fopen.login.yahoo.com%2Fopenid%2Fyrp%2Fsc_check&cancel_url=https%3A%2F%2Fopen.login.yahoo.com%2Fopenid%2Fyrp%2Fsc_check&perms=user_birthday%2Cuser_likes%2Cemail%2Cpublish_actions&response_type=code&locale=en_US
When i try to do this using FB's javascript SDK:
FB.ui({
method: 'permissions_request',
perms: 'read_stream,publish_stream,user_photos',
display: 'iframe'
},
function(response){
alert("badfood");
alert(response);
});
It goes to a different endpoint: facebook.com/dialog/permissions_request? ...
And I get a 500 server error from facebook without useful debug info.
Thanks
some things.
1) first add the parameter show_error=true. This will tell you more about what's really causing the error.
2) Facebook has multiple ways it can display any dialog. In the fiddler request, note the display=iframe parameter. This is used for canvas applications mainly but can be useful for regular iFrame displays as well. It opens the auth dialog in a lightbox.
3) Try loading the SDK synchronously. Remove the Async references that Facebook tells you to include at the top of the page after the body tag and use the secondary method. Include the all.js and fb-root div tag and load FB.init just before your FB.ui call.
4) Check out the echo tool.
This tool can print out your GET params or your . It can also decode
the signed_request parameter as used in Canvas applications with the
OAuth 2.0 Beta migration enabled. This is very useful in debugging
Canvas Authentication.
http://developers.facebook.com/docs/reference/dialogs/
Loading the auth/permissions dialogs inside iframes are not permitted nor possible due to the risk of clickjacking. Sites where you see this being done have special agreements with Facebook that allows them to do this.
Trying to track sources of Likes to a Facebook Page. Docs from Facebook say:
ref - a label for tracking referrals; must be less than 50 characters and can contain
alphanumeric characters and some punctuation (currently +/=-.:_). The ref attribute causes
two parameters to be added to the referrer URL when a user clicks a link from a stream story
about a Like action:
fb_ref - the ref parameter
fb_source - the stream type ('home', 'profile', 'search', 'other') in which the click
occurred and the story type ('oneline' or 'multiline'), concatenated with an underscore.
But if you are sending Likes to a Facebook Page - NOT an external website - where can you get this fb_ref data? Appears that it's not available in Insights, and you can't put Google Analytics on a Wall, obviously.
Any insights here?
My understanding is that you would use it as follows:
Jim is logged into your site.
Put a FB like button on a page on your web site. You're generating the page dynamically so you can generate the FB like button dynamically too. Since "Jim" is logged in, you can include "Jim" as the ref in the FB Like button.
Jim, an FB user, LIKES the page, and presses the Like button (that includes the Jim ref).
A link to your web page appears on Jim's FB page and all of his friends see it.
Susan, a FB friend of Jim, sees the "Like" about your website on Jim's wall (it appears in her newsfeed.) Excited about the link, she presses it.
Your website receives an incoming GET request from Susan's browser. It includes the ref=Jim. It also includes the fb_source="profile" This tells your page about the requestor.
Your website now displays the page to Susan. The page (dynamically) includes the greeting "Thanks for being a friend of Jim!" etc. Note, you don't know the requestor is Susan, you only know that the requestor found out about the page via Jim's Like of the page. In order to find out that the person is Susan, you need to get her to signin/signup for your website.
Docs for the extra Get params: see the description of the ref param here
Added
Re: But if you are sending Likes to a Facebook Page - NOT an external website - where can you get this fb_ref data? Appears that it's not available in Insights, and you can't put Google Analytics on a Wall, obviously.
Do you mean that you're creating a Like button for a page on Facebook that is not a FB app? AFAIK you're right, you can't see the ref data. The ref data is made available to the target of the Like.
You could create a simple website page that re-directs to the FB page. You'd then collect ref info before re-directing to the FB page. Your simple re-direct page would be the target of the Like. But you'd have to fake out FB's graph tags--they'd know that the canonical url for the page was fb.com/xyz. May not be possible to direct to your_site.com/fb/xyz.
Using the Graph API I'd like to be able to have an authorized user "like" a page.
I tried posting the following
https://graph.facebook.com/${PAGE_ID}/likes?access_token=${ACCESS_TOKEN}
And I get an HTTP error 500 accompanied by "Invalid post_id parameter" in the JSON response body. Looks like the /likes resource is suited to liking a wall post and not a page. How do I get this to work with a page?
Facebook has announced support for liking URL's outside of Facebook by using the official built-in Like action. You need to have publish_actions permissions. The graph url for this is:
https://graph.facebook.com/[User FB ID]/og.likes?object=OG_OBJECT_URL&access_token=USER_ACCESS_TOKEN
However, you cannot use this to like a page on Facebook currently, as the documentation states:
For Facebook Pages or websites that do not integrate with Facebook
Authentication, developers should continue to use the Like button
social plugin.
Update June 2016
It's still not possible to like a page using Facebook API, as stated in the /{user_id}/likes documentation page about Creating/Updating/Deleting:
You can't perform this operation on this endpoint.
In previous versions the message was clearer (see the quote below), but the result is the same: it's not possible.
May 2014
The /{user-id}/likes documentation page States about Publishing Likes of Facebook Pages:
You can't publish using this edge, as it is not possible to like a Facebook Page via any API. You should use the Like Button if you want people to be able to like a page in your app.
This is the most obvious and clear statement that has been able to give me an answer to the question.
if your app is an open graph app, now you can like using the api, and no need for the button anymore.
https://developers.facebook.com/docs/opengraph/actions/builtin/likes/
If you want this functionality in a page tab or canvas page within facebook (say to allow for liking the page from within a likegated page), a work around you can involves what Tom Wells suggested in his reply to Luke. You first embed the iframe version of their like button on your page, and then simply listen for the edge.create event in your JS like so:
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
// ...
}
);
In the callback, you can deal with with what happens when the user has liked the page, say like navigating away from the like-gate page, or showing liked-only content.
When the user clicks the iFrame like button, your JS code should receive the edge.create event assuming the iFrame was configured to point to the url of the page in question.
I believe this is not allowed except for specific partner sites, like yelp. The reason is security, you would be able to put some javascript on a page and have everyone that visits that page "Like"ing it without their knowledge.
See How do I "Like" a URL? on the Facebook Platform Developer Forum
You can like an object with its object id using Facebook api using the following piece of code
[FBRequestConnection startForPostWithGraphPath:[NSString stringWithFormat:#"/%#/likes",{object_id}] graphObject:nil completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
//do you customisation post like here
}];