Twitter API resource for Windows 8 metro application - c#

I'm developping an application that uses Twitter API to collect informations about users.
I'm using linqToTwitter in my current project but it does not allow me a lot of thing that I want to do.
For example I need getting a follower list of a searched user.
LinqToTwitter allowed me finding a user who the name is given and who is in the follower list of the authenticate user.
The code is the following:
public List<User> RecupererFollower()
{
var friendship =
(from friend in MainPage.twitterCtxProp.Friendship
where friend.Type == FriendshipType.FollowersList
&& friend.SourceScreenName==MainPage.texte
select friend).ToList();
Followers = (from friend in friendship
select new User //Un utilisateur est créé grâce aux données récupérées précédemment.
{
Name = friend.ScreenName
}).ToList(); //Cette partie constitue la liste de tweets récupérés précédemment.
return Followers;
}
But even this doesn't work because this query requires a specific screenName of a particular user.
I don't want this I want more general functions.
What can I do?
Someone knows other resources for Windows 8 metro application?

The #millimoose comment, "an API client library will probably only give you access to the API itself" is quite accurate. The particular query you're trying to use is documented at Handling Friendships. The documentation also refers to the original Twitter endpoint that it supports, which is Followers List in this case. On this particular API, the Twitter documentation states that either user_id or screen_name is required. The library can't support more than is available.
That said, you'll have to look at what's available and can sometimes accomplish your goal. i.e. There are also Social Graph queries that are very efficient because they return User IDs. With those User IDs, you can do a UserType.Lookup query to gather multiple users at a time. Here are a few links for UserType.Lookup queries:
Get all followers using LINQ to Twitter
How to get tweets from a multiple of friends?

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 API get subsribers of a page?

I've been searching the Graph API Explorer and documentation for a long time, but I really can't find anything.
I need a simple GET request like the me/subscribes just with page-id/subscribers or something like that. Does anyone know the get I must send to get a Count of subscribers of a page?
BTW I'm using Facebook SDK and I'm using this as GET:
var fb = new FacebookClient(useraccesstoken);
dynamic result = fb.Get("i want to get subscribers of a page id what to do??");
The /me/subscribers end-point was available to users' only, and has since been removed with Graph API 2.0, along with the user_subscriptions permission.
You can get a count of the subscribers / likes for a page as follows:
/{page-id}?fields=likes
This will return an a count for the total number of likes for a given {page-id}:
{
"likes": 123456,
"id": "{page-id}"
}
Trying to access the subscribers of a page is the same as trying to access all the users that have liked the page, which Facebook doesn't allow.

Using Facebook API to access public group event data

I'm developing a public website and what I want to do is pretty straightforward, but I'm pulling my hair out trying to get everything working right.
I administer an open Facebook group and I want to display the public facebook events of this group on my website.
I can't seem to figure out how to setup my authentication so that I can access the event data. Here is my code for using my application to get an auth token:
var fb = new FacebookClientWrapper();
dynamic result = fb.Get("oauth/access_token", new
{
client_id = AppSettings.AppID,
client_secret = AppSettings.AppSecret,
grant_type = "client_credentials"
});
fb.AccessToken = result.access_token;
I know this works fine because I can access some information - for example, if I access a specific event by its ID, I can retrieve that information.
The problem occurs when I try to retrieve a list of events with fields within a date range:
[HttpGet]
public object GetEventDetails(string unixStartDateTime, string unixEndDateTime)
{
var parms = new Dictionary<string, object>();
parms.Add("fields", new[] { "id","name","description","start_time","venue" });
if (!String.IsNullOrEmpty(unixStartDateTime)) { parms.Add("since", unixStartDateTime); }
if (!String.IsNullOrEmpty(unixEndDateTime)) { parms.Add("until", unixEndDateTime); }
var eventsLink = String.Format(#"/{0}/events", AppSettings.GroupID);
return ObjectFactory.GetInstance<IFacebookClient>().Get(eventsLink,parms);
}
(I'm aware that even if this did succeed, the return value wouldn't be serializable - I'm not concerned about that quite yet).
This GET request returns the following message:
(OAuthException - #102) A user access token is required to request this resource.
So the message is quite clear: I need a user access token to get the data I've requested. The question is - what is the best way to do this? Can I give my application a certain permission to read this data? I've looked over all the permissions available to apps, but I don't see one that would do the trick.
I don't want to require people to log onto Facebook to look at public event data, and I love the idea of allowing people with no technical experience to essentially update the website content by posting Facebook events to the group. Right now, I have to duplicate anything they do.
I would think this kind of application would be very common, but no matter what I've read or tried, I can't quite find an example of the same thing that works.
From the docs at https://developers.facebook.com/docs/graph-api/reference/v2.0/group/events you need
A user access token for a member of the group with user_groups permission.
To avoid the hassle, you could create such an Access Token via the Graph Explorer and then store it in your application. Remember to exchange that Access Token to a long-lived one (https://developers.facebook.com/docs/facebook-login/access-tokens/#extending), and that you have to renew the Access Token every 60 days afterwards.

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/

Get list of invited friends from MultiFriendSelector

I am using ASP.net C# for a web application that integrates with the Facebook API. My application will allow users to create a group for sharing code. I need to use Facebook API to let the user invite friends from Facebook to join his group on my application. This is a requirement for an assignment so please don't give suggestions to create a group of users that are registered with my site only.
Until now I have the request dialog with all the friends listed (MultiFriendSelector()) with this code:
<p> Click <span id="span-link" onclick="sendRequestViaMultiFriendSelector(); return false;">here</span> to add friends from your Facebook account to your group! </p>
But I am stuck on how to get the id's and details of these invited users so I can save them in my database and allow them to access the group they were invited to. How can I do this please? I can't seem to find anything related to this.
By the way I know that there is a related question which gives this code:
if( Request["ids"] != null )
((Site)Master).FbInviteSent(Request.QueryString.GetValues("ids"));
but I don't know what Master is and I cant get it to work.
Thanks for your help :)
Whenever you call the request dialog, you may pass a callback function:
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'My Great Request'
}, requestCallback);
}
The requestCallback will receive the response, and this response returns the facebook id of the users, who were invited
function requestCallback(response){
for (var i = 0; i < response.to.length; i++) {
fb_id = response.to[i];
// Do something with fb_id.
}
}
From looking at the code in the other answer it looks like the facebook API will call back to your page with a query string parameter of ids.
I.e. It will call you site with a url like this.
http://wwww.yoursitesulr.com/mypage.aspx?ids=13,22,44
You can then pull out the id's from the query string using
string myIds = Request.QueryString["ids"];
You can then convert them to a array.
var ids = myIds.Split(',');
If you are using MVC then you can take advantage of the model binders and just put an int array in your view model and it will get bound automatically.
The answer below addresses your specific issie so I would use this as a starting point.
Faceboook: Posting to Multiple Friend's Walls Using Multiple Friend Selector and JS SDK
Let me know if you have any questions regarding the above solution.
Regards
Steve

Categories

Resources