Facebook Graph API: how do I retrieve my own posts? - c#

I'm trying to write a program which retrieves my own posts and comments from facebook - I'm able to login and retrieve information about "me", but I got no idea how to get the posts I've written. I find the graph API documentation very confusing.
I'm using a c#/WPF assembly which lets me retrieve the information about me using:
fbApp.GetAsync("me", (val) =>
{
var result = (IDictionary<string, object>)val.Result;
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
new Action(delegate() { InfoBox.ItemsSource = result; }));
});
Using which graph API I can retrieve my own posts and/or comments?

You simply retrieve your Feeds by a GET Request to
http://graph.facebook.com/me/feed
for comments
http://graph.facebook.com/[post-id]/comments

Related

How to get Teams Organization Hierarchical data in C# using Graph API

In microsoft teams, there is a tab titled "Organization", which shows something like this:
Is there any way I can get this data in C# by using Graph API?
Right now I have
var users = await graphClient.Users.Request().GetAsync();
which returns an array of all users, and each user has their name and job title. This is not enough to make the org chart, because it does not tell how different users relate. What Graph API call do I need to make in order to get the data to make the org chart?
If you are using Microsoft Graph SDK for C#, you can use the code below to get users with the manager:
var usersWithMgr = await graphServiceClient.Users.Request().Expand("manager").GetAsync();
Result:
I found out you can make a graph call to users to get all users in a domain, then foreach user, make a call as listed here: https://learn.microsoft.com/en-us/graph/api/user-list-manager?view=graph-rest-1.0&tabs=csharp
This will get the manager, which can be manipulated into a hierarchical view.
UPDATE:
var users = await graphClient.Users.Request().Expand("manager")
.Select(u => new { u.DisplayName, u.JobTitle, u.AccountEnabled}).GetAsync();

Facebook page /feed missing images

I was using the Facebook Public API Feed for the longest time and since they deprecated it I've been trying to find a replacement method in C#.
I am able to get my page posts but any post that contains images I only get the message and no images. After spending the past weekend trying to find a way I am desperate to know if anyone has had any success in getting full page post content from the Facebook C# SDK library.
Here is what I have and it works for getting the posts but they do not contain any images.
var fb = new FacebookClient
{
AppId = ConfigurationManager.AppSettings.Get("FacebookAppID"),
AppSecret = ConfigurationManager.AppSettings.Get("FacebookAppSecret"),
AccessToken = ConfigurationManager.AppSettings.Get("FacebookAccessToken")
};
var pageFeed = string.Format("/v2.4/{0}/feed", _facebookPageId);
dynamic response = fb.Get(pageFeed);
Since the upgrade in Graph API v2.4. Only a limited set of data is sent via FB unless specifically requested. You should pass the fields parameter with the keyword of data which you would like to retrieve.
A list of keyword is available here
In your case, the request statement would be:
var pageFeed = string.Format("/v2.4/{0}/feed?fields=id,message,picture", _facebookPageId);
To get all pictures from a post: replace picture with attachments, as picture will return the very first picture linked to the post.
var pageFeed = string.Format("/v2.4/{0}/feed?fields=id,message,attachments", _facebookPageId);

Get facebook feed for particular users C#

I am developing a server application that should be able to react to the amount of likes for some of the posts in the user's feed.
I need to get post from users wall.
I'm using Facebook library version 6.4.2
I use the following code to get the posts:
var apiKey = ConfigurationManager.AppSettings["apiKey"];
var secret = ConfigurationManager.AppSettings["secret"];
var client = PostHandler.CreateFacebookClient(apiKey, secret);
var get = client.Get(string.Format("/{0}/feed", pageId));
and/or (both return the same info)
var token =ConfigurationManager.AppSettings["token"];
var get = client.Get(string.Format("/{0}/feed?access_token={1}", pageId, token));
The problem is that using the same set of permissions the json returned from the request above is different from the json returned from json returned from Graph API Explorer methog GET 100000481752436/feed
In my opinion the json returned from my request is missing some posts and the one from the Geaph API all contains the posts from my feed.
Could you please advice, what could I have missed ?
If you are missing some posts in the feed it is most likely that you'll have to check the permissions set again.
Based on the type of posts you are missing you maybe have to add the user_status, user_activities, user_friends, user_checkins or user_games_activity permissions. Please make sure that you're using the correct set of the permissions for your particular task.
If you'll specify the type of the posts you are missing you may get much more helpful answers.

How to get the friends activities using twitter api?

I am not able to get list or collection from twitter api which returns my friends activities.
Basically I want the list of activities of my friends just like the twitter has activity or interaction section on its website.
You can do that with a Site stream. First, get a list of your friends ID's, then add them to the site stream. Here's an example using LINQ to Twitter:
Console.WriteLine("\nStreamed Content: \n");
int count = 0;
(from strm in twitterCtx.UserStream
where strm.Type == UserStreamType.Site &&
strm.Follow == "15411837,16761255"
select strm)
.StreamingCallback(strm =>
{
Console.WriteLine(strm.Content + "\n");
if (count++ >= 10)
{
strm.CloseStream();
}
})
.SingleOrDefault();
You can find more info in the LINQ to Twitter Documentation.
Also, regardless of what technology you go with, you should read Twitter's Site Streams documentation.
NOTE: Twitter site streams is in Beta, so you'll need to contact them for access.
To be able to monitor your friends on Twitter you need to use the UserStream (https://dev.twitter.com/docs/streaming-apis/streams/user).
Whilst its implementation is missing some features of the UserStream the Tweetinvi API gives the ability to easily detect what your friends do on twitter.
Here is an example :
// Register the Twitter Credentials
IToken token = new Token("userKey", "userSecret", "consumerKey", "consumerSecret");
// Create the stream
IUserStream userStream = new UserStream();
// Register to an event that triggers when a tweet is created by a user you follow
userStream .TweetCreatedByAnyoneButMe += (sender, args) =>
{
Console.WriteLine("Tweet '{0}' created by {1}!", args.Value.Text, args.Value.Creator.Id);
};
// Start the stream
userStream.StartStream(token);
This code is going to call the Console.Writeline() each time a Tweet is created by a user you follow!
As I said all the features are not implemented yet but you can already listen to many different events like Tweets, Messages, Follows... as well as filtering the Tweets you receive (which is not possible by default with Twitter UserStream).
Hope this will help you :)
EDIT : You can find the API there -> http://tweetinvi.codeplex.com/

How to get friends list from facebook? (Desktop application)

As per this link code from stack overflow i have try this code for getting
friendslist but after login i got this error "requires valid signature"
string APIKey = ConfigurationManager.AppSettings["API_Key"];
string APISecret = ConfigurationManager.AppSettings["API_Secret"];
Facebook.Session.ConnectSession connectsession = new Facebook.Session.ConnectSession(APIKey, APISecret);
Facebook.Rest.Api api = new Facebook.Rest.Api(connectsession);
var friends = api.Friends.GetLists();
foreach (var friend in friends)
{
System.Console.WriteLine(friend.name);
}
guide me to find out the solution
Thanks
ash
If you are starting with a new application, you should definitely use the Graph API and not the old Rest API. The Rest API has been deprecated for quite a while now and there is no guarantee how much longer Facebook will support it.
For an example on using the Graph API try http://csharpsdk.org/docs/web/getting-started
You can obtain the friends list by making a request to me/friends
You can test other requests using the Graph API explorer.

Categories

Resources