I am posting to Facebook using c#
private static void PostToPage(string message)
{
var fb = new FacebookClient("My Little Pony Facebook token is Magic");
var argList = new Dictionary<string, object>();
argList["message"] = message;
fb.Post("feed", argList);
}
But I get this Posted via Graph Api Explorer on the face book wall (check this IMAGELINK). Any way I can customise this to make it more personal like Posted By user
See this SO Discussion:
Replace "via Graph API Explorer" label by my application name
If it says 'via Graph API Explorer' on the posts your app makes you're
using the access token you retrieved when you were testing the API
using the Graph API Explorer tool, not one produced by your own app
Related
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");
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");
}
}
Can you please tell me via a code sample how I can write a C# program that will call
the Google+ API and Custom Search API of Google.
I know there is a brief description of it on :::::
URL:https://developers.google.com/+/api/
URL:https://developers.google.com/custom-search/v1/using_rest
URL:http://code.google.com/p/google-api-dotnet-client/wiki/OAuth2
But the process mentioned in the links in doing the above as given in the documentation is
not very clear.
Is there a simple illustration through C# code that I can use to call Google+ API and Custom
Search API?
The Google API Dotnet Client project contains .NET wrappers form most of Google's APIs, including Google+.
They do have several examples but not for all of their APIs, yet.
A Google+ example from their page to query for public activities is:
CommandLine.EnableExceptionHandling();
CommandLine.DisplayGoogleSampleHeader("PlusService API");
// Create the service.
var objService= new PlusService();
objService.Key = ""; //put in user key.
var acts = objService.Activities.Search();
acts.Query = "super cool";
acts.MaxResults = 10;
var searchResults = acts.Fetch();
if (searchResults.Items != null)
{
foreach (Activity feed in searchResults.Items)
{
//extract any property of uer interest
CommandLine.WriteResult(feed.Title, feed.Actor);
}
}
I'm developing an asp.net MVC 3 Facebook app and I am trying to post a message to my wall. Here is my code:
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);
I can get the access token using client.AccessToken, so I'm assuming I don't have to set it anywhere. This code produces no errors and for the result I get an ID. However, when I bring up my Facebook, I see nothing on my wall nor in my news feed. I'm not sure what I'm missing. I've looked at related questions here at StackOverflow, but I see no reports/questions similar to mine. I've also tried changing the code based on what I've seen in other posts, but to no avail. I also checked my Facebook account settings and I see my application listed with permission to post to my wall. I also tried posting a message to my wall via the Graph API explorer and I'm getting the same result. I get an ID in return, but when I check my Facebook account I see nothing. At been at this for a couple of days. Any help would be greatly appreciated.
Thanks in advance.
[EDIT]
I wonder if something is wrong with my app generated access_token. Using this access_token, as I mentioned in my post, I get the same result using the Graph API explorer. An ID is returned, but no message on my wall. However, if I give the Graph API explorer permission to post to my wall and use its own generated access_token, I can successfully post a message using the explorer. Here's the FB login button code:
<div>
<h1>Login using Facebook</h1>
<p><fb:login-button perms="user_location, publish_stream, email"></fb:login-button></p>
</div>
Basically you need to add an additional parameter into your post parameters.
args["access_token"] = account.access_token;
this is the token of the specific page.
I wont repeat the code, follow here for example: Post On Facebook Page As Page Not As Admin User Using Facebook C# SDK
(second answer)
Did you request right App permissions to Facebook in your action method?
Try: [CanvasAuthorize(Permissions = "user_location, publish_stream, email")]
Did you append the access_token to the URL? See example here. It's also documented here (see Using the Access Token).
/me/feed?access_token=<access_token>
with one small change, your code works fine for me. you have to pass the users auth token into the constructor like this...
var client = new FacebookClient(accessToken);
// 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);
this method works for me, although i am not sure which facebook sdk you are using.
i'm using http://facebooksdk.net/ its quite good so if you're not using it i would recommend it
I'm a refugee from the old Facebook Developer Toolkit porting my app to the newer Facebook C# SDK. I've got the MVC web app side of my solution worked out, but I also have a console application that I run in batch as part of my overall solution. I obtain the offline_access extended permission for all of my users and store the non-expiring session key for later use in my console app.
With the Facebook Developer Toolkit I was able to spin up a Connect Session and REST api using my API Key, API Secret, and the saved user session key and make Facebook api calls.
In the Facebook C# SDK the non-web samples seem to rely on popping up some kind of browser control for interactive user login. That won't work for a console batch application processing users offline.
I've got this far:
string oAuthAccessToken = "{access token}"
var app = new Facebook.FacebookApp(oAuthAccessToken );
// now I can make api calls like this:
dynamic currentPermissionsJson = new ExpandoObject();
currentPermissionsJson = app.Query(string.Format("SELECT publish_stream, offline_access, email from permissions where uid = {0}", {userid}));
var currentPermissions = ((JsonArray)currentPermissionsJson)[0] as IDictionary<string, object>;
and away we go.
I'm just stuck on how to convert my existing stored session keys to Facebook OAuth access tokens. I can see how I can construct POSTs to https://graph.facebook.com/oauth/exchange_sessions with params such as
client_id={my app id}
&client_secret={my app secret}
&sessions={previously stored session keys}
and get the access token back in the response.
But I'm thinking the SDK must offer some method of doing this for me. Or does it?
Unfortunately, we dont have any helpers in the current Facebook C# SDK to exchange the access tokens. I have created an issue and I will try to get it in there shortly. http://facebooksdk.codeplex.com/workitem/5788
For now I wrote up this. Give it a try and let me know how it works:
public class FacebookOAuth
{
public static IEnumerable<ExchangeSessionResult> ExchangeSessions(string appId, string appSecret, params string[] sessionKeys)
{
WebClient client = new WebClient();
var dict = new Dictionary<string, object>();
dict.Add("client_id", appId);
dict.Add("client_secret", appSecret);
dict.Add("sessions", String.Join(",", sessionKeys));
string data = dict.ToJsonQueryString();
string result = client.UploadString("https://graph.facebook.com/oauth/exchange_sessions", data);
return Newtonsoft.Json.JsonConvert.DeserializeObject<ExchangeSessionResult[]>(result);
}
}
public class ExchangeSessionResult
{
[Newtonsoft.Json.JsonProperty("access_token")]
public string AccessToken { get; set; }
[Newtonsoft.Json.JsonProperty("expires")]
public string Expires { get; set; }
}