如何获取Google Plus的帖子数据(喜欢 - 分享 - 评论)?

时间:2012-04-07 10:47:20

标签: c# .net api c#-4.0 google-plus

使用C#,我想阅读Google +帖子的分享,评论和喜欢,例如https://plus.google.com/107200121064812799857/posts/GkyGQPLi6KD

1 个答案:

答案 0 :(得分:7)

该帖子是一项活动。 This page包含有关如何获取有关活动信息的信息。 This page提供了一些使用API​​的示例。 This page下载了Google API .NET库,您可以使用该文档访问Google+ API,使用XML文档等。

您需要使用API Console获取API密钥并管理您的API使用情况。

另请查看API Explorer

这是一个有效的例子:


引用Google.Apis.dll和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();

输出:

    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