How to get the friends activities using twitter api? - c#

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/

Related

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.

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

Twitter API resource for Windows 8 metro application

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?

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

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

How to see if a user is following you on Twitter using C# Twitter API wrapper Tweetsharp

I see there is a API call for Frienships/Show, but I am not sure how to parse the response to get the true/false.
Here is my code so far:
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs(_userName, _password)
.Friendships().Verify(_userNameToCheck)
.AsJson();
var response = twitter.Request();
Also, once authenticated, how to do set a user to follow you?
With TweetSharp you can access the friendships/exists API this way:
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs(_username, _password)
.Friendships()
.Verify(_username).IsFriendsWith(_userNameToCheck)
.AsJson();
There is no way to "set a user to follow you", they have to choose to follow you on their own.
There is an API for that listed in the API Wiki. The document can be found here. This will simply return true if it user A is following user B.
Here is a list of Libraries that probably support what your after.

Categories

Resources