Pinterest Getting information about a given user

Getting information about a given user

When requesting information about a Pinterest user, you need to either specify the username or the ID of that user.

The Pinterest API will only return a few fields by default. Currently the default fields are the id, first name, last name and the URL of the user's profile page. If you need further information about the user - eg. statistics or the profile image of the user, you need to specify this explicitly.

In its simplest form (with default fields), you make a call similar to the one shown below:

@using Skybrud.Social.Pinterest.Objects.Users
@using Skybrud.Social.Pinterest.Responses.Users

@inherits System.Web.Mvc.WebViewPage<Skybrud.Social.Pinterest.PinterestService>

@{

    // Make the call to the API
    PinterestGetUserResponse response = Model.Users.GetUser("skybruddk");
    
    // Get the user object
    PinterestUser user = response.Body.Data;
    
    // Print some information about the user
    <p>Id: @user.Id</p>
    <p>First name: @user.FirstName</p>
    <p>Last name: @user.LastName</p>
    <p>Url: @user.Url</p>
    
}

Fields

When you make a call to the API like the one above, the API will respond what Pinterest calls a partial response.

With Skybrud.Social you can specify the fields to be returned through an instance of PinterestFieldsCollection. The most basic fields can be accessed through the static properties in the PinterestUserFields class.

@using Skybrud.Social.Pinterest.Fields
@using Skybrud.Social.Pinterest.Objects.Users
@using Skybrud.Social.Pinterest.Responses.Users

@inherits System.Web.Mvc.WebViewPage<Skybrud.Social.Pinterest.PinterestService>

@{
    
    // Collection of fields to be returned by the API
    PinterestFieldsCollection fields = new PinterestFieldsCollection();
    fields.Add(PinterestUserFields.Username);
    fields.Add(PinterestUserFields.FirstName);
    fields.Add(PinterestUserFields.LastName);
    fields.Add(PinterestUserFields.Counts);
    fields.Add(PinterestUserFields.Image);

    // Make the call to the API
    PinterestGetUserResponse response = Model.Users.GetUser("skybruddk", fields);
    
    // Get the user object
    PinterestUser user = response.Body.Data;
    
    // Print some information about the user
    <h3>Basic information</h3>
    <p>Id: @user.Id</p>
    <p>Username: @user.Username</p>
    <p>First name: @user.FirstName</p>
    <p>Last name: @user.LastName</p>
    
    // Print some user statistics
    if (user.HasCounts) {
        <h3>Counts</h3>
        <p>Followers: @user.Counts.Followers</p>
        <p>Following: @user.Counts.Following</p>
        <p>Pins: @user.Counts.Pins</p>
        <p>Boards: @user.Counts.Boards</p>
        <p>Likes: @user.Counts.Likes</p>
    }
    
}