【问题标题】:How to get Google Plus's post data ( likes - shares - comments )?如何获取 Google Plus 的帖子数据(点赞-分享-评论)?
【发布时间】:2012-04-07 10:47:20
【问题描述】:

使用 C#,我想阅读类似 https://plus.google.com/107200121064812799857/posts/GkyGQPLi6KD

的 Google + 帖子的分享、评论和喜欢

【问题讨论】:

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


    【解决方案1】:

    该帖子是一项活动。 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
    

    【讨论】:

    • 如果我们有这个帖子(活动)plus.google.com/114277819599398268182/posts/eoNrpWWF9KY什么是活动ID?当我尝试“eoNrpWWF9KY”时,它给了我:“无法找到 ID 为 eoNrpWWF9KY 的活动”
    • ActivityFeed 包含来自用户的所有活动。您可以遍历 ActivityFeed.Items 以找到满足某些要求的项目,然后使用它的 ID。在这种情况下,您需要一个特定的 URL,所以我使用了它。这个ID是“z13qd5zouuebcpauy23tuftwdsylxflvs”。对于 eoNrpWWF9KY,它是“z12tsvgjwyvawtzr104cixjqrsm1j5pxjyk0k”。
    • @ Kiran Price - 请告诉我如何获取帖子的活动 ID
    猜你喜欢
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    • 2012-09-04
    • 2012-11-04
    • 1970-01-01
    • 2015-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多