Get Facebook objects information with C# - c#

I'm new to facebook development. I'm using C# on Windows Form and I'm searching for a way to get information about a post on facebook.
I've read documentation and see that I can use FQL to query facebook object.
My questions:
is using FQL it a good way in WindowsForm solutions ?
I need to get the count on how many 'like' are done on an object (link or photo). Can I do this with like Table ?
I need to know who is sharing my facebook objects (link or photo). Where is the relative Table I can use ?
Thanks for your help.

I haven't had a lot of luck with FQL and prefer to use the graph api
Using this in combination with the facebook SDK dll you can quickly retrieve information about a post as a json object using the following code.
var client = new FacebookClient(accessToken);
var jsonPost = (JsonObject) client.Get(postId);
As for seeing who has shared your objects I'm not sure if that can be done using the graphAPI, you would be able to see likes and comments of a object by using
var client = new FacebookClient(accessToken);
var jsonLikes = (JsonObject) client.Get(postId + "/likes");
var jsonComents = (JsonObject) client.Get(postId + "/comments");

Related

Not getting Twitter api statuses

I am trying to use the following twitter API, but am unable to get user statuses. Tell me what is the error?
WebClient connectTwitter = new WebClient();
connectTwitter.DownloadStringCompleted += new
DownloadStringCompletedEventHandler(connectTwitter_DownloadStringCompleted);
connectTwitter.DownloadStringAsync(new
Uri("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=BarackObama"));
You need to authenticate in order to access the Twitter API.
You'll probably want to start here: https://dev.twitter.com/docs/auth/tokens-devtwittercom, and you might want to consider using a C# wrapper for the API, like this: https://github.com/danielcrenna/tweetsharp.

How do I get Google Calendar feed from user's access token?

Using OAuth I do get access token from Google. The sample that comes with Google and even this one:
http://code.google.com/p/google-api-dotnet-client/source/browse/Tasks.SimpleOAuth2/Program.cs?repo=samples
show how to use Tasks API. However, I want to use Calendar API. I want to get access to user's calendar. Can anybody tell me how do I do that?
Take a look at the samples:
Getting Started with the .NET Client Library
On the right side of the page linked above there is a screen shot showing the sample projects contained in the Google Data API solution. They proofed to be very helpful (I used them to start my own Google Calendar application).
I recommend keeping both your own solution and the sample solution open. This way you can switch between the examples and your own implementation.
I also recommend to use the NuGet packages:
Google.GData.AccessControl
Google.GData.Calendar
Google.GData.Client
Google.GData.Extensions
and more ...
This way you easily stay up to date.
Sample to get the users calendars:
public void LoadCalendars()
{
// Prepare service
CalendarService service = new CalendarService("Your app name");
service.setUserCredentials("username", "password");
CalendarQuery query = new CalendarQuery();
query.Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full");
CalendarFeed calendarFeed = (CalendarFeed)service.Query(query);
Console.WriteLine("Your calendars:\n");
foreach(CalendarEntry entry in calendarFeed.Entries)
{
Console.WriteLine(entry.Title.Text + "\n");
}
}

Get the List of all Flikr PhotoSets using Flikr.net API

I am trying to add the name of all photosets into a list box.I have the Token and a Valid Flickr Object.How can i do this in c#.In the standard Flikr API
flickr.photosets.getList
is used but how can i achieve this in .net
Ripped from here
Flickr Library in C#
The last few days I've been working on a sample C# library to access Flickr pictures using Flickr's own API. This library is a light-weight C# class that provides two basic features: (1) retrieve the list of photosets in your account and (2) retrieve information about the photos in a photoset.
Using this class you can retrieve the photosets in your Flickr account and display them in a combobox with a few lines of code like these:
Flickr flickr = new Flickr("YourApiKey", "YourUserID");
List<PhotoSetInfo > photosets = flickr.GetPhotoSets();
cboPhotoSets.DataSource = photosets;
cboPhotoSets.DataTextField = "Title";
cboPhotoSets.DataValueField = "PhotoSetID";
cboPhotoSets.DataBind();
Once you select a photoset you can retrieve information about the photos inside it (like title and URL) with the following code. In this example I am binding the list of photos to an ASP.NET datalist control to display them:
Flickr flickr = new Flickr("YourApiKey", "YourUserID");
List<PhotoInfo> photos = flickr.GetPhotosInSet(cboPhotoSets.SelectedValue);
listPhotos.DataSource = photos;
listPhotos.DataBind();
lblPhotosMsg.Text = (photos.Count == 0) ? "No photos in this photoset" : "";
The Flickr API supports multiple requests and response formats. I am using the REST format for requests and responses in my FlickrLib library. A typicall Flickr REST request looks like this:
http://api.flickr.com/services/rest/?method=methodName&parameter1=value1&parameter2=value2
where methodName is the name of the method to call, for example flickr.photosets.getList to return a list of photosets.
REST responses that Flickr provide are XML documents with the pertinent information for the request. For the flickr.photosets.getList method the reponse would be an XML document with a photosets node and several photoset children nodes. These XML responses are very easy to parse with LINQ to XML and turn them into C# strong-typed objects (like PhotoSetInfo and PhotoInfo) which then can be bound to .NET classes. That's exactly what the FlickrLib library does, it provides a wrapper to the Flickr API functionality so that you can easily consume it from your .NET applications.
References
You can download the C# source code for this class from http://hectorcorrea.com/downloads/FlickrLibDemo.zip
For information about the Flick API visit http://www.flickr.com/services/api/ there is a lot of information there on what the API provides and how to use it. There are tons of Flickr features that the API provide that you might find useful and that my little class does not expose.
You will need to obtain an API key from Flickr in order to use their API through this class or any other class. The API key is free but it is needed so that Flickr can prevent a single user from submitting too many requests to their site and take it down.
Posted on 11/30/2008 12:27:00 PM Perma Link

facebook C# sdk- comparing from id and userid

using feed dialogue i m posting some data to wall using my app..
but when my friend go to view this feed , its shows the app for itself only..
the reason is i am checking the from id parameter in request.params bt since i m using access token to access user info in graph api, it overlaps the previous params and only code with access token is dere in request..
how to resolve it..??
Well, i dont get what you're asking about exactly , but if you post anything to any user's wall, you should get authorized first, and i think you know that already as you mentioning.
So after you get the access token, you can do that to post anything to the user's wall, assuming that you're using Facebook C# SDK as mentioned in the title:
FacebookClient fbClient = new FacebookClient("AccessToken"); //replace your access token with that..
dynamic me = fbClient.Get("/me");
Dictionary data = new Dictionary();
data.Add("message", txtStatusContent.InnerText.Trim());
fbClient.Post("/me/feed", data);
And that's it.

Is there anything out there that will make it easy for me to allow my users to share their Facebook photos (and videos) on my site?

I see a bunch of .NET open source projects out there that look to be able to get at the users information, but I just want a user to be able to "post" media that's already on Facebook on my site as well. Other websites seem to allow you to do embedding of their media (I'm really liking oEmbed) but FB seems a bit of a mystery to me. I have no experience using their API, but I'm guessing it has something to do with the "social graph" part. Anyone else done this before? Did you use something or is this easy enough to do without these OS projects? Any examples anywhere of how someone already did this? I wouldn't think that I'm the first person to want to do this but have searched Google and didn't come up with anything.
Have you tried FQL? Using this I was able to get users display pictures on any site I wanted by simply constructing a simple SQL like query.
The Facebook .NET SDK makes this very easy for you. You can download it here: http://facebooksdk.codeplex.com
Here is an example of how you would publish a photo using that SDK:
string photoPath = #"..\..\..\Facebook.Tests\bin\Release\monkey.jpg";
byte[] photo = File.ReadAllBytes(photoPath);
FacebookApp app = new FacebookApp();
dynamic parameters = new ExpandoObject();
parameters.message = "The message you want to go with the photo...";
var mediaObject = new FacebookMediaObject {
FileName = "monkey.jpg",
ContentType = "image/jpeg",
};
mediaObject.SetValue(photo);
parameters.source = mediaObject;
dynamic result = app.Api("/the_album_id/photos", parameters, HttpMethod.Post);
string photoId = result.id;

Categories