Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Dec 02, 2014 @ 13:58
    Ismail Mayat
    0

    Social followers

    For youtube / twitter and facebook is it possible via api to get follower counts for given account or do we have to extend to do that?

    Cheers

    Ismail

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    Dec 02, 2014 @ 15:22
    Anders Bjerner
    0

    Hi Ismail,

    For Twitter, you can look up the user at read the followers count from the FollowersCount property on the user object.

    Facebook has a /me/subscribers method, but according to their upgrade guide to version 2.0 of the Facebook API, the method has been removed. However it still seems to be working when I do a test. I don't know of any other ways to get the subscribers count. If you manage to find something in the API documentation, I'd be happy to add it to Skybrud.Social.

    I haven't yet focused on users in the YouTube API, so I don't know what is possible there.

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    Dec 02, 2014 @ 19:29
    Anders Bjerner
    102

    For Twitter

    int followers = service.Users.GetUser("abjerner").FollowersCount;
    

    For YouTube

    Version 2 of the Google API allows you to get the subscriber count for a given user, but that version was deprecated in the spring.

    Version 3 doesn't work with users, but channels instead. Considering that you have an active instance of GoogleService and sufficient permissions to access the YouTube API, you can do the following:

    NameValueCollection query = new NameValueCollection();
    query.Add("part", "id,snippet");
    query.Add("forUsername", "Battlefield");
    query.Add("access_token", service.Client.AccessToken);
    
    string response = SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://www.googleapis.com/youtube/v3/channels", query);
    
    dynamic json = JsonConvert.DeserializeObject<JObject>(response);
    
    int subscriberCount = json.items[0].statistics.subscriberCount;
    

    It is only a quick snippet - I will add better support for it later in Skybrud.Social. The snippet also lacks error handling , and it is only tested with a user that has a single channel.

    For Facebook

    As I wrote earlier, this seems to be deprecated as of v2.0, but it still works. You can exchange me with a valid identifier.

    string res = SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://graph.facebook.com/v2.2/me/subscribers?access_token=" + service.Client.AccessToken);
    
    dynamic json = JsonConvert.DeserializeObject<JObject>(res);
    
    int subscriberCount = json.summary.total_count;
    
  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Dec 02, 2014 @ 20:02
    Ismail Mayat
    0

    Anders,

     

    Awesome will give a whirl timmorow.

     

    Regards

     

    Ismail

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Dec 04, 2014 @ 10:41
    Ismail Mayat
    0

    Anders,

    Got the twitter user followers working nicely, love this library its going to save some time h5yr!!!

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft