Search code examples
c#.netgoogle-plus

How to get Google Plus's post data ( likes - shares - comments )?


Using C# , I want to read the Shares , Comments and Likes of a Google + post like this https://plus.google.com/107200121064812799857/posts/GkyGQPLi6KD


Solution

  • That post is an activity. This page includes infomation on how to get infomation about activities. This page gives some examples of using the API. This page has downloads for the Google API .NET library, which you can use to access the Google+ APIs, with XML documentation etc.

    You'll need to use the API Console to get an API key and manage your API usage.

    Also take a look at the API Explorer.

    Here's a working example:


    Referencing Google.Apis.dll and Google.Apis.Plus.v1.dll

            PlusService plus = new PlusService();
            plus.Key = "YOURAPIKEYGOESHERE";
            ActivitiesResource ar = new ActivitiesResource(plus);
            ActivitiesResource.Collection collection = new ActivitiesResource.Collection();
    
            //107... is the poster's id
            ActivitiesResource.ListRequest list = ar.List("107200121064812799857", collection); 
            ActivityFeed feed = list.Fetch();
    
            //You'll obviously want to use a _much_ better way to get
            // the activity id, but you aren't normally searching for a
            // specific URL like this.
            string activityKey = "";
            foreach (var a in feed.Items)
                if (a.Url == "https://plus.google.com/107200121064812799857/posts/GkyGQPLi6KD")
                {
                    activityKey = a.Id;
                    break;
                }
    
            ActivitiesResource.GetRequest get = ar.Get(activityKey);
            Activity act = get.Fetch();
            Console.WriteLine("Title: "+act.Title);
            Console.WriteLine("URL:"+act.Url);
            Console.WriteLine("Published:"+act.Published);
            Console.WriteLine("By:"+act.Actor.DisplayName);
            Console.WriteLine("Annotation:"+act.Annotation);
            Console.WriteLine("Content:"+act.Object.Content);
            Console.WriteLine("Type:"+act.Object.ObjectType);
            Console.WriteLine("# of +1s:"+act.Object.Plusoners.TotalItems);
            Console.WriteLine("# of reshares:"+act.Object.Resharers.TotalItems);
    
            Console.ReadLine();
    

    Output:

        Title: Wow Awesome creativity...!!!!!
        URL:http://plus.google.com/107200121064812799857/posts/GkyGQPLi6KD
        Published:2012-04-07T05:11:22.000Z
        By:Funny Pictures & Videos
        Annotation:
        Content: Wow Awesome creativity...!!!!!
        Type:note
        # of +1s:210
        # of reshares:158