1

I'm using the Google Plus API for .NET, and I would like to get a picture's URL, shared by a friend today.

How can I get it?

It allows me to get a list of activities and moments, but I don't see what I want.

ActivitiesResource.SearchRequest req = Program.GooglePlusService.Activities.Search("awesome");
ActivityFeed feed = req.Fetch ();
4

1 回答 1

2

首先,我要注意:

搜索 API 将返回 Google+ 搜索的全局结果。没有办法以编程方式读取特定用户的 Google+ 信息流(例如,用户访问 plus.google.com 时看到的内容)。此外,您只能检索公开的活动。

也就是说,当您检索活动提要时,您可以遍历活动并找到带有附件的活动,如下所示:

    String nextPageToken = "";
    do
    {
        ActivitiesResource.SearchRequest req = ps.Activities.Search("awesome");
        req.PageToken = nextPageToken;

        ActivityFeed feed = req.Fetch();
        nextPageToken = feed.NextPageToken;

        for (int i = 0; i < feed.Items.Count; i++)
        {
            if (feed.Items[i].Object.Attachments != null)
            {
               // the activity has associated content you can retrieve
                var attachments = feed.Items[i].Object.Attachments;
            }
        }
    }while(nextPageToken != null);

另一种方法是使用 Activities.list 方法获取与当前授权用户相关的人员列表。您将执行 people.list 请求以查看当前用户的连接人员,然后列出他们的公共提要”

    // Get the PeopleFeed for the currently authenticated user.
    PeopleFeed pf = ps.People.List("me", PeopleResource.CollectionEnum.Visible).Fetch();                

    String nextPageToken = "";
    for(int personIndex = 0; personIndex < pf.Items.Count; personIndex++)
    {
        ActivitiesResource.ListRequest req = ps.Activities.List(pf.Items[personIndex].Id, ActivitiesResource.Collection.Public);
        req.PageToken = nextPageToken;

        ActivityFeed feed = req.Fetch();
        nextPageToken = feed.NextPageToken;

        for (int i = 0; i < feed.Items.Count; i++)
        {
            if (feed.Items[i].Object.Attachments != null)
            {
                // the activity has associated content you can retrieve
                var attachments = feed.Items[i].Object.Attachments;
            }
        }
    }
于 2013-06-13T00:19:19.770 回答