facebook sdk invite friends to application - c#

I want to allow users to invite friends to a facebook app through the Facebook c# sdk. I'm not keen on using the popups or any flakey meta language. is there a way to do this without resorting to popups?

invite facebook friend from your application or website,use this small lines of code and send invitation to all facebook friends to visit your website.i also used this script its working nicely.
your domain must be ssl certified because facebook not allowing unsecured domains.
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'APP_ID',
cookie:true,
status:true,
xfbml:true
});
function FacebookInviteFriends()
{
FB.ui({
method: 'apprequests',
message: 'Your Message diaolog'
});
}
</script>
//HTML Code
<div id="fb-root"></div>
<a href='#' onclick="FacebookInviteFriends();">
Facebook Invite Friends Link
</a>

The best way to do this is via Requests 2.0. That is what FB recommends.
There is a blog post about it on Facebook Developers here:
http://developers.facebook.com/blog/post/464/
It's actually quite simple:
FB.init({
appId:'YOUR_APP_ID', cookie:true,
status:true, xfbml:true
});
FB.ui({ method: 'apprequests',
message: 'Here is a new Requests dialog...'});
Behind the scenes, FB has made it a bit trickier to track the requests, but with the C# SDK it's just a graph call.

Using c# Facebook SDK on codeplex (facebooksdk.codeplex.com), you can send invitations to your friends by the following codes:
var fb = new FacebookWebClient();
dynamic parameters = new ExpandoObject();
parameters.appId = "{yourAPPid}";
parameters.message = "{yourmessage}";
dynamic id = fb.Post("me/apprequests", parameters);
Best of Luck!

Related

Accessing facebook for posts etc with Graph API c# unity3d

I'm using C# in MonoDevelop with the Graph API to interact with users facebook pages.
I've become thoroughly confused though.
Are these the correct steps?
create facebook app Here : http://developers.facebook.com/
programmaticly get access token using app ID and app Secret.
If so how do I go from this to posting to users walls?
I've done lots of research but have been unable to find anything particularly useful.
I've tried using this ASP.NET Post to Facebook Wall but Nothing ever appears on the wall.
Is there a tutorial or something that can take me through the process nice and slow?
All help or pointers appreciated.
As stated i'm working with unity3d, c# in mono and the facebook graph api.
[Edit] I'd like it to work on android.
Use the C# Facebook library. There is a sample project called facebook-aspnet-sample which shows you authentication and login. Also, have a look at this tutorial page which deals with how to connect from a Unity3d game to Facebook. The tut is short but the demo project download is useful.
There are also plugins for sale that enable Facebook access from Unity3d.
after your have your FB app ready, indeed, you need to get a token. However, token is always requested in the context of a USER - and therefore user should authenticated on the website. That means that Facebook login dialog should be displayed - which will ask user if he indeed trusts the application. There are different ways to do this - here is the generic page about FB authentication: https://developers.facebook.com/docs/authentication/, and this one explains how to do this in Android: https://developers.facebook.com/docs/mobile/android/sso/
if you want to go with JavaScript authentication (which I personally use in MVC3 project), here is a little bit modified example from https://developers.facebook.com/docs/authentication/client-side/ which does this. Remember to change app id and permissions to the ones you need.
<div id="fb-root"></div>
<script>
// Load the SDK Asynchronously
(function (d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
} (document));
// Init the SDK upon load
window.fbAsyncInit = function () {
FB.init({
appId: '#EventController.FB_APP_ID', // App ID
channelUrl: '//' + window.location.hostname + '/channel.htm', // Path to your Channel File
status: false, // check login status
cookie: false, // enable cookies to allow the server to access the session
xfbml: false // parse XFBML
});
// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', function (response) {
if (response.authResponse) {
// user has auth'd your app and is logged into Facebook
FB.api('/me', function (me) {
// get info about the user, for example
})
//document.getElementById('auth-loggedout').style.display = 'none';
} else {
// user has not auth'd your app, or is not logged into Facebook
//document.getElementById('auth-loggedout').style.display = 'block';
}
});
// respond to clicks on the login and logout links
document.getElementById('auth-loginlink').addEventListener('click', function () {
FB.login(function (response) {
// handle the response
if (response.authResponse != null) {
// HERE IS THE TOKEN YOU CAN USE
var token = response.authResponse.accessToken;
} else {
}
// AND THESE ARE THE PERMISSIONS YOU WANT YOUR APP TO REQUEST
}, { scope: 'manage_pages,publish_stream' });
});
};
</script>
One catch here - your FB app should have your website URL (even if it is http://localhost/) in App -> Settings -> Website URL field. Also you should put channel.htm file into the root of your website with one line of code in it:
<script src="//connect.facebook.net/en_US/all.js">

Posting emdedded HTML and JavaScript to Facebook

I know how to post a message, etc. to a Facebook wall, but I want to post a custom HTML and JavaScript Facebook wall, and I want that HTML/JavaScript code to appear so users can use that from Facebook without leaving Facebook, like embedded YouTube videos I have seen this to be possible...
I use this to post to Facebook:
FacebookWebClient client = new FacebookWebClient();
// Post to user's wall
var postparameters = new Dictionary<string, object>();
postparameters["message"] = "Hello world!";
postparameters["name"] = "This is a name";
postparameters["link"] = "http://thisisalink.com;
postparameters["description"] = "This is a description";
var result = client.Post("/me/feed", postparameters);
How do I do this?
Maybe something like
postparameters["html"] = "html or view";
If it is not possible, how do I post SWF content with Flash parameters?
There is no way to post custom HTML or JavaScript code into a Facebook post because of security issues.
But you can still customize a lot of stuff like the link and the image, if you want to add an action link next to "Like, comment".
Find a lot more about publishing a post in Core Concepts › Graph API › Post.
if it is not possible, how do I post SWF content with Flash parameters?
To post an SWF video, you will need to do some work.
First, create a page that the SWF videos lives on where you can specify Open Graph meta tags. Read
more in The Open Graph protocol.
Then you need to create a post with a link to that page with the Open Graph tags. Then use the "link" parameter of the post object to point to the SWF file.

Facebook registration protocol

I am making a marketing tool that is required to register facebook accounts using web requests. I have been trying to understand the protocol but I always end up with a "Sorry there is something went rong" page. Any explanations are appreciated =].
Regards
edit: I am trying to let the user to register on facebook through my application. He should input the required fields (names,birthday,email) and the application should do the signup process for him after he solves the captcha that will be fetched from facebook. It's not a spam attempt, Don't bother saying you won't answer because it's a spam attempt. If you think so, just don't answer.
edit: I don't want to use any WebBrowser controls, I need it to be through HTTP Requests.
edit: I try to imitate requests sent to facebook from my computer using fiddler, I believe I imitated everything that facebook website does. Though I still getting "Sorry something went wrong" page.
You have several API to to that. I recommend that you use the last one, the graph API. Then you have several SDK, I know PHP and Javascript SDK.
In javascript, with jQuery you can do
<body>
<div>
<button id="login">Login</button>
<button id="logout">Logout</button>
<button id="disconnect">Disconnect</button>
</div>
<div id="user-info"></div>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
// initialize the library with the API key
FB.init({ apiKey: 'YOUR_API_KEY' });
// fetch the status on load
FB.getLoginStatus(handleSessionResponse);
$('#login').bind('click', function() {
FB.login(handleSessionResponse, {
// here you specify the perms your application requires
perms:'publish_stream, offline_access, manage_pages, read_stream'
});
});
$('#logout').bind('click', function() {
FB.logout(handleSessionResponse);
});
$('#disconnect').bind('click', function() {
FB.api({ method: 'Auth.revokeAuthorization' }, function(response) {
clearDisplay();
});
});
// no user, clear display
function clearDisplay() {
$('#user-info').hide('fast');
}
// handle a session response from any of the auth related calls
function handleSessionResponse(response) {
// if we dont have a session, just hide the user info
if (!response.session) {
clearDisplay();
return;
}
// if we have a session, query for the user's profile picture and name
FB.api('/me/accounts', function(response) {
$('#user-info').html(JSON.stringify(response));
});
}
</script>
</body>
This example is taken from the documentation of the JavaScript SDK. You need to get you API_KEY from the facebook developper page http://www.facebook.com/developers/apps.php

Inviting users to a pre-existing facebook event using the REST API

What is the best way to invite users to an existing event? We'd like to do the following:
create an event, make it public
while on our (external) website give the user a dialog (fb:multi-friend-selector) to select their friends to invite to the event
It's established the new Graph API can't be used (http://bugs.developers.facebook.net/show_bug.cgi?id=10070), but the documentation for the REST API (http://developers.facebook.com/docs/reference/rest/events.invite) implies that it's not possible to invite users to existing events.
If anyone could provide any clarity on this I'd be grateful - reading the vague and contradictory facebook documentation is getting me nowhere.
Specifically, who/where/how should the event be created? - and how can I then invite users to that event from an external website?
This can be done using the Graph API. To use the JavaScript SDK use the following:
FB.api('/[EVENT-ID-HERE]/attending', 'post');
This can only be done once you have an authenticated user, so in full, the code would be:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId: '[APP-ID-HERE]', cookie: true, status: true, xfbml: true
});
FB.Event.subscribe('auth.login', function (response) {
if (response.session) {
FB.api('/[EVENT-ID-HERE]/attending', 'post');
}
});
</script>
<fb:login-button perms="rsvp_event">Attend Event</fb:login-button>

Facebook c# sdk Fork: Version5 oAuth

First, please excuse me because i speak english like a french cow!
This is it, i have decided to get off the Facebook Toolkit and start to use the Facebook c# sdk.
I looked at the v4.2.1. Then i read "http://facebooksdk.codeplex.com/Thread/View.aspx?ThreadId=241181" and i downloaded the v5 source code.
I've got a little problem with the auth process with this V5.
Here is my code:
string _requiredAppPermissions = "offline_access,email";
FacebookApp fbApp = new FacebookApp();
var fbSettings = new FacebookSettings();
fbSettings.AppId = RWE.Core.Config.FacebookApp;
fbSettings.AppSecret = RWE.Core.Config.FacebookSecret;
Authorizer authorizer = new Authorizer(fbSettings);
//Authorizer authorizer = new Authorizer();
if (!String.IsNullOrEmpty(_requiredAppPermissions)) authorizer.Perms = _requiredAppPermissions;
authorizer.Perms = _requiredAppPermissions;
authorizer.ReturnUrlPath = _AuthUrlReturn;
authorizer.Authorize();
var me = fbApp.Api("me");
So if i load the app from the url : "http://apps.facebook.com/myapp", it displays a facebook logo with (in french) "Accéder à Facebook" (which means 'access to facebook'). The link is kind of "http://www.facebook.com/connect/uiserver.php?app_id=170580299646394&method=permissions.request&display=page&next=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&response_type=code&fbconnect=1&perms=offline_access%2Cemail"
If i load the app from "http://realurl.com", it displays directly the authorisation form like it should be in the facebookapp url.
My questions are :
How can i have the auth form displayed directly (without the facebook logo step) ?
While i specify a ReturnUrlPath, facebook still uses facebook.com/connect/login_success.html and leads me to facebook.com instead of going back to the app. How can i change that ?
Make sure you specify target="_top" for your <a> tag.
<a href="..." target="_top" />

Categories

Resources