Snekithan
Snekithan

Reputation: 500

How to get the URL of an image shared to me today?

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 ();

Upvotes: 1

Views: 142

Answers (1)

class
class

Reputation: 8681

First, I'll note:

The search API will return global results for searches across Google+. There is not a way to programmatically read the Google+ stream (e.g. what the user sees when they go to plus.google.com) for a particular user. Furthermore, you can only retrieve activities that are public.

That said, when you retrieve the activities feed as you are doing, you can loop through the activities and find the ones with attachments as follows:

    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);

An alternative would be to use the Activities.list method for the list of people connected to the currently authorized user. You would perform a people.list request to see the current user's connected people and then list their public feeds"

    // 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;
            }
        }
    }

Upvotes: 2

Related Questions