i want to develop Desktop based application in wpf (c#). which will need option to login their facebook account too. so i have registered my app in fb developer site and download C# sdk with reference some stack overflow link. which always give connection failed
// code which i have used
string APIKey = ConfigurationManager.AppSettings["API_Key"];
string APISecret = ConfigurationManager.AppSettings["API_Secret"];
Facebook.Session.ConnectSession connectsession = new Facebook.Session.ConnectSession(APIKey, APISecret);
if (connectsession.IsConnected())
{
Facebook.Rest.Api api = new Facebook.Rest.Api(connectsession);
var friends = api.Friends.GetLists();
foreach (var friend in friends)
{
System.Console.WriteLine(friend.name);
}
}
some site telling that C# sdk is deprecated.
http://developers.facebook.com/blog/post/624/
Facebook Graph C# SDK Ver 6.0: Unable to create event on App's Page
please help me to start facebook api integration in my desktop based app using wpf. some body asked to use graph api but i have doubt whether this will supprot for c# . am struk to start my step on facebook integration.
Graph Api is fully supported in C# because it is based on rest and you can call rest service through C# code, obviously url calling is different from method calling, In graph api you can call url and parse its response. I would recommend to go with graph api, Facebook has not provided the C# SDK, its a open source library maintained by open source community, however graph api help is directly provided by Facebook.
Check here and here to know how to call graph api through C#
Related
Hi I'm currently refreshing my knowledge in C# programming.
I wanted to translate the manual way of creating a Web App in Microsoft Azure (Classic) into the C# language.
(Manual way - New > Compute > Web App > Custom Create > ...etc.. )
Whenever I search through google about this topic all it gives me is to literally create a "WebApp" in Visual Studio. (File > New > ...etc...) However, what I am looking for is how to create an Azure Web App programatically via C# - how to interact with the Management UI of the Classic Azure Portal to create a web app.
Anyone familiar to do this? Thanks in advance for the help! :)
To create an azure website easily using C#, you can use "Windows Azure Management Libraries". This SDK is a wrapper arround "Azure Service Management" API.
Here is a introduction from Braddy Gaster an a blog post, to get credentials from an Azure Tenant an work with ASM Api.
Then you will be able to create a website with something like this :
using (var AwsManagement = new Microsoft.WindowsAzure.Management.WebSites.WebSiteManagementClient(azureCredentials))
{
WebSiteCreateParameters parameters = new WebSiteCreateParameters()
{
Name = "myAws",
// this Service Plan must be created before
ServerFarm = "myServiceplan",
};
await AwsManagement.WebSites.CreateAsync("myWebSpace", parameters, CancellationToken.None);
}
I was able to work on the available code Microsoft posted in GitHub:
https://github.com/Azure/azure-sdk-for-net
I re-coded some and just acquired the functions that I only need for my program to work. :)
You can create a web site by using a POST request that includes the name of the web site and other information in the request body. You can check the code example for ASM here.
With Twitter's new OAuth interface, their API is now many times more complex than what it was. And I haven't even looked at Facebook's API yet.
What I'm wondering if there is a method that employs some higher-level, existing code or interfaces to make this a simpler task.
All I want to be able to do is initiate a Twitter tweet or Facebook share on the user's behalf and be able to control the initial text of those messages, from an ASP.NET application.
I found some similar questions on SO, but they had no answers.
EDIT: I know there are things like AddThis and ShareThis, but I need something that will give me control over the default message. It must contain a link with a code that is specific to the current user.
Twitter Integration...
For making Tweets from an ASP.NET application on users' behalf, check out Twitterizer. It's a free, open-source project for integrating with Twitter from .NET applications.
I agree that using OAuth can be a bit daunting, but the Twitterizer API wraps up most of the complexity. I've written an article on using Twitterizer in an ASP.NET application that you may be interested in: Integrating Twitter Into An ASP.NET Website Using OAuth. After reading the article, download the code sample at the end, which is a working demo showing how to use Twitterizer to post a tweet from an ASP.NET website.
Facebook Integration...
For integrating with Facebook, chcek out the Facebook Developer Toolkit. Like Twitterizer, it's an open-source, free API and should get you going in the right direction.
Happy Programming!
After looking around for a while, I found sharethis.com. They have various share buttons you can add to your site that send Twitter tweets, Facebook shares, etc.
It looks like it also supports options to control the URL, so I could modify this to include whatever URL I need.
I haven't yet figured out if I can control the default message text. I'm looking into that.
But it seems like this is probably the simplest way to accomplish what I want.
This is probably what you're after for twitter: https://twitter.com/about/resources/buttons#tweet
Let's you configure a button (or URL to redirect to) that starts the user off with some default text. The user can change the text before they post.
Don't know about facebook.
Twitter Integration:
Check this code and link/article simple and easy :
protected void btnTweet_Click(object sender, EventArgs e)
{
string oauthAccessToken = Session["twtoken"].ToString();
string oauthAccessTokenSecret = Session["twsecret"].ToString();
OAuthHelper oauthhelper = new OAuthHelper();
oauthhelper.TweetOnBehalfOf(oauthAccessToken, oauthAccessTokenSecret, txtTweet.Text);
if (string.IsNullOrEmpty(oauthhelper.oauth_error))
Response.Write("Twit Posted Successfully");
else
Response.Write(oauthhelper.oauth_error);
}
Read more how to get access token and secret key and download OAuthHelper and OAuthUtility Class below is the link -
How to post tweet on behalf of an user from asp.net using oauth authentication
Login with twitter using oauth authentication in asp.net and get access token, screen name and userid
Is there a way to create a Resource Group with the Azure Management C# API?
Basically this REST API call:
https://msdn.microsoft.com/en-us/library/azure/dn790525.aspx
I found a way to create an Affinity Group by using client.AffinityGroups.Create, but that's the closest thing I've found.
I found the API call was hidden in a library which is only in preview mode at the moment. It's found in the following NuGet package, enable include prerelease in Visual Studio to find it in the NuGet client.
https://www.nuget.org/packages/Microsoft.Azure.Management.Resources/
Then to create a resource group I can use
var credentials = new TokenCloudCredentials("", "");
var client = new Microsoft.Azure.Management.Resources.ResourceManagementClient(credentials);
var result = c.ResourceGroups.CreateOrUpdateAsync("MyResourceGroup", new Microsoft.Azure.Management.Resources.Models.ResourceGroup("West US"), new System.Threading.CancellationToken()).Result;
There is another stack overflow post explaining how to do the authentication:
How to get Tags of Azure ResourceManagementClient object
The following blog post explains how to set up TokenCloudCredentials, required for the authentication part, in more detail, but only for command line apps:
http://www.bradygaster.com/post/using-windows-azure-active-directory-to-authenticate-the-management-libraries
If you want to use something other than a command line app the following can work for authentication:
http://www.dushyantgill.com/blog/2015/05/23/developers-guide-to-auth-with-azure-resource-manager-api/
Go to https://resources.azure.com - the ARMExplorer shows both the REST and the PowerShell commands to create a resource group. All the APIs are REST based. In C#, send a WebClient request.
I have setup up a .NET console application that will do the following:
Access the Google Contacts API for my personal Google Account
Perform basic CRUD (create, read, update, delete) operations to these contacts
I believe executing the CRUD operations will be straight forward using the following documentation:
https://developers.google.com/google-apps/contacts/v3/#about_authorization_protocols
However, my problems are occurring when trying to authenticate my connection using OAuth2.0.
I am using the Google.GData.Contacts .NET NUGET Package using the code from the following example:
https://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/oauth2_sample/oauth2demo.cs?r=1159
OAuth2Parameters parameters = new OAuth2Parameters() {
ClientId = clientId,
ClientSecret = clientSecret,
RedirectUri = redirectUri,
Scope = scopes
};
string url = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
Console.WriteLine("Authorize URI: " + url);
parameters.AccessCode = Console.ReadLine();
OAuthUtil.GetAccessToken(parameters);
As this code was last updated in 2012, I'm worried it might no longer be relevant for my task.
Major Questions:
I'm not sure exactly what the parameters.AccessCode value is. Where does this value come from?
Based upon my use case am I using the correct OAuth2.0 approach? You can can setup authentication for a Service Account, Web Application, or Native Application. The above code implies Native Application
Is there a better way to handle my task?
The access code should be used only for WebServer Applications.
I'm not sure if your console app will run in an environment where a browser can be launched or not.
If yes (your app is running in a environment where a URL can be launched), use the documentation for Installed Applications.
If browser is not present, you can use the documentation for Applications on limited-input devices.
If the library you're targeting to use (NUGET, whatever) has no support for this flow, don't worry: it's easy to write custom code. You can use any library able to do HTTP/HTTPS requests, like or Windows.Web.Http.HttpClient (Windows 8 and later).
Additionally, you can use contact import services like CloudSponge, which offers a .Net API and support for other contact sources (in case you want expand your address book support in the future).
AccessCode comes from the URL created in that Line above. See here:
string url = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
url contains a URL now for your browser. Fill it in Chrome/Firefox/etc and confirm the google request to get the AccessCode. It will look like this "4/bAQT1qf66vpkmfU8xDkoVZmedvVoYDH6KovzcHcA5pc" but will change every time you call the URL.
Console.WriteLine("Authorize URI: " + url);
now you can see the url but you might not be able to copy it from your console. But if you get it into your browser, it will result in a google dialog to get your AccessCode.
I use Facebook Connect for login on my website and need to create functionality of sending personal messages to user's Facebook friends.
A solution from this question is not suitable for me because I need to send messages to several friends at the same time (user just selects friends from the list who she/he wants to send a message).
I've found pretty good post about this question for Ruby - How to send private messages with Facebook API. But I can't find a C# package similar to xmpp4r_facebook Ruby gem.
agsXMPP SDK and jabber-net don't support X-FACEBOOK-PLATFORM SASL mechanism (http://forum.ag-software.de/thread/1372-Facebook-Chat and Connect to facebook chat using Jabber.net (C#/Mono) with SASL).
I hope to find some existing solution instead of updating one of these libraries. Or to find some library like xmpp4r_facebook but for .NET platform.
Thanks.
The latest sources of agsXMPP supports the X-FACEBOOK-PLATFORM Sasl mechanism.
1) checkout the latest sources
2) add the following code to the OnSaslStart event
private void XmppCon_OnSaslStart(object sender, SaslEventArgs args)
{
args.Mechanism = Mechanism.GetMechanismName(agsXMPP.protocol.sasl.MechanismType.X_FACEBOOK_PLATFORM);
args.ExtentedData = new FacebookExtendedData {AccessToken = "YOUR TOKEN", ApiKey = "YOUR API KEY"};
}
Facebook does not allow the SDK to send private messages to prevent misuse by spammers