4

使用 C#,我想阅读这样的 Google + 帖子的Shares、Comments 和 Likes https://plus.google.com/107200121064812799857/posts/GkyGQPLi6KD

4

1 回答 1

7

那个帖子是一个活动。此页面包含有关如何获取有关活动的信息的信息。此页面提供了一些使用 API 的示例。此页面包含 Google API .NET 库的下载,您可以使用它来访问 Google+ API,以及 XML 文档等。

您需要使用API 控制台来获取 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
于 2012-04-07T11:23:11.070 回答