Code Monkey home page Code Monkey logo

pinsharp's Introduction

PinSharp

license AppVeyor Coverage CodeFactor NuGet FOSSA Status

An async C# wrapper library for the Pinterest API.

Notice

I'm not maintaining this regularly as I don't use it that much. If you have any issues or request please create a new issue and I'll have a look.

Overview

New in version 2.0

A lot of the changes are code cleanup and refactoring, but there is a few new features.

Rate limit information

Information about rate limits are now stored on the PinSharpClient in the property RateLimits

It contains information about the request limit and remaining requests and when this information was last updated (i.e. the time of your last request through this client).

Exceptions

The client now throws its own exceptions all extending from PinSharpException.

For example a PinSharpRateLimitExceededException will be thrown if the rate limit has been exceeded.

Breaking changes in version 2.0

All return types have generally been changed from a concrete class to an interface, e.g. Pin to IPin. BoardDetails and UserDetails have also been renamed in the process to IDetailedBoard and IDetailedUsers.

Renamed

  • PinterestClient renamed to PinSharpClient
  • PinterestAuthClient renamed to PinSharpAuthClient
  • PinterestApi made internal
  • Scopes.WriteRelationShips renamed to Scopes.WriteRelationsships

Moved

  • PinSharp.IHttpClient moved to PinSharp.Http.IHttpClient
  • PinSharp.Models.ImageInfo moved to PinSharp.Models.Images.ImageInfo

Refactored/combined

  • Models
    • BoardDetails removed - merged into Board and exposed as IDetaildBoard interface
    • UserDetails removed - merged into User and exposed as IDetailedUser interface
    • UserBoard removed - merged into Board and exposed as IUserBoard interface
    • UserPin removed - merged into Pin and exposed as IUserPin interface
  • Counts
    • BoardCounts removed - merged into new Counts and exposed as IBoardCounts interface
    • PinCounts removed - merged into new Counts and exposed as IPinCounts interface
    • UserCounts removed - merged into new Counts and exposed as IUserCounts interface
  • Images
    • BoardImages removed - merged into new ImageList and exposed as IBoardImageList interface
    • PinImages removed - merged into new ImageList and exposed as IPinImageList interface
    • UserImages removed - merged into new ImageList and exposed as IUserImageList interface

Examples

You need an access token to use the API.

If you don't have one already you can generate one here: https://developers.pinterest.com/tools/access_token/

// Create a client with your access token
var client = new PinSharpClient("AB_IBS7Q0fFQbXJ90JGtSDXNMV-tEBkfLftbK6JCpEWkGoA_MwAAAAA");

// Get board information
var board = await client.Boards.GetBoardAsync("machineshopcafe/best-of-mclaren-machine");

// Get pins on board
var pins = await client.Boards.GetPinsAsync("machineshopcafe/best-of-mclaren-machine");

// Get pins on board but only with the 'board' field as dynamic or your own type
var pins = await client.Boards.GetPinsAsync<dynamic>("rice_up/tableware", new[] { "board" });

// Get user info of the user associated with the access token
var user = await client.Me.GetUserAsync();

// Get pins of the user associated with the access token
var pins = await client.Me.GetPinsAsync();

// Get boards of the user associated with the access token
var boards = await client.Me.GetBoardsAsync();

// Search the associated user's pins or boards
var pins = await client.Me.SearchPinsAsync("mclaren");
var boards = await client.Me.SearchBoardsAsync("mclaren");

// Create new pin
var newPin = await client.Pins.CreatePinAsync("machineshopcafe/best-of-mclaren-machine", "http://i.imgur.com/abcdef.jpg", "Looks so cool!");

// Follow/unfollow board or user
await client.Me.FollowBoardAsync("machineshopcafe/best-of-mclaren-machine");
await client.Me.UnfollowBoardAsync("machineshopcafe/best-of-mclaren-machine");
await client.Me.FollowUserAsync("machineshopcafe");
await client.Me.UnfollowUserAsync("machineshopcafe");

License

FOSSA Status

pinsharp's People

Contributors

dependabot[bot] avatar fossabot avatar krusen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pinsharp's Issues

Create pin api is failing

CreatePinAsync fails most of the times with an error message: "Unexpected character encountered while parsing value: \u001f. Path '', line 0, position 0."

However the post is published.

I could not managed to find a clearly way how to reproduce it. A specific request just simply fails in one time but in the next try works again.

I was debugging it and seems that the response has a wrong encoding.

Board Not Found

I'm calling var newPin = await client.Pins.CreatePinAsync() and the response says that the board is not found, yet I was able to iterate through the boards and the one listed in my list is the exact name I used to pin an image.

Do I have to prefix the board name with something?

Thanks, Glenn

Create Board & Change Title?

Is there a method to not only get the pinterest boards but also create boards?

When pinning an image, is there an overloaded method to pass the Title of the pin when the pin is created?

Getting App Approved?

Hi Again,

Do I need to have my App approved by Pinterest to use your API?

What is the advantages of getting the App approved?

Thanks, Glenn

Add XML Documentation

Models

  • Board/IBoard
  • Pin/IPin
  • User/IUser
  • RateLimits/IRateLimits
  • Counts/IBoardCounts/IPinCounts/IUserCounts
  • ImageInfo/IBoardImageList/IPinImageList/IUserImageList

Exceptions

  • PinSharpException
  • PinSharpAuthorizationException
  • PinSharpBadRequestException
  • PinSharpForbiddenException
  • PinSharpNotFoundException
  • PinSharpRateLimitExceededException
  • PinSharpServerErrorException
  • PinSharpTimeoutException

API

  • PinSharpClient
  • PinSharpAuthClient
  • IBoardsApi
  • IMeApi
  • IPinsApi
  • IUsersApi
  • PagedResponse<T>
  • IHttpClient

Other

  • InterfaceConverter<T>

error on fetching pin from a board

Hi

when i am trying to fetch pins from board named deepthr3e/virtual-reality-video-gaming I found that when fetching a specific pin the exception thrown "Error reading string. Unexpected token: StartObject. Path 'attribution.embed', line 1, position 425." i investigate the error and found that the issue
in the specific pin we have an object named "Attribution" and in this object have an object named "embed
"and your code doesn't have this object
here an image of the hierarchy of the json of pins https://s3.postimg.org/gui81hpyb/Capture.png

this is the full address of board: https://www.pinterest.com/abolhasani1149/error-board/
and this is the very pin that causes the issue: https://www.pinterest.com/pin/679128818779898527/

Token v5 Not Working - Always Null

I created a token for v5 of Pinterest but when calling PinSharpClient and adding the registered token the results are always null. Looks like the response is null. Can you please take a look at this? As of right now I can not read or post anything.

VS Plugins / Configuration

I wanted to add support for the Rate Limiting information to be returned.

It seems I might need to have VS extensions installed to work on the project, can you let me know what they are so I can do a PR?

Thanks

Is code Works on 2019?

Hello, me program using your nuget package "not work" for me show in debug "Unauthorized".

using PinSharp;
using PinSharp.Api;

private async void Button_X(object sender, RoutedEventArgs e)
        {
            // Create a client with your access token
            var client = new PinSharpClient("SECRET_APP");

            // Create new pin
            var newPin = await client.Pins.CreatePinAsync("glopesdasilvasa/testes", "https://i.imgur.com/Q9rcBQo.jpg", "Looks so cool!");
        }

I try to create a application to publish in 3 social networks simultaneously, I started with pinterest using the your code.

In app manager on Developers.pinterest.com "App Secret" I copy and past in debuting token and shows not valid. The what this? Interfer to show error "Unathorized"?

Sorry my english is poor

How to Catch API Rate Limit Exception using PinSharp

Hi,

How to catch API Rate Limit Exception? We have PinterestAPIException block, but whenever rate limit exceeds this will hit to Generic catch block and shows exception message as "Value cannot be null".

Please let me know how to check Current Limit, Remaining Limit using PinSharp.

Need API Details for reference

Hello @Krusen
I am reaching out to you to get some better details on Pinterest API. I am looking for an API from Pinterest which gives me the list of users against a specific search criteria and list of boards against specific search criteria. Do you know if such APIs exist? I am trying hard to get accurate answer here. Please note that, my application cannot generate token for each users. So I will be generating the token once with required scopes and interested in getting list of valid users and boards (public boards from other users).

I am also observing that the stackoverflow community talks about V2 and V3 APIs from pinterest, but i am not seeing any details. Is it like pinterest will be launching new API version in near future? Please let me know if you have any insight on this.

Thanks
Nilesh

Authorization Failed ?

Here is my code. I have my app set up but get the Authorization Failed exception message when trying to get the boards. Please Advise.

private async void GetBoardsBTN_ClickAsync(object sender, EventArgs e)
{
// Create a client with your access token
var client = new PinSharpClient("APP SECRET");

        // Get boards of the user associated with the access token
        var boards = await client.Me.GetBoardsAsync(); // Throws Authorization Failed exception
    }

Functions Not Working

Hi Soren,

I have been working with your wonderful library for some time now and just discovered these 2 function don't work. I have the latest version installed. Runtime Version: v4.0.30319 - Version: 2.2.6.0

string boardid = "667588413453034663";

// Get board information
var myboard = await client.Boards.GetBoardAsync(boardid);

{"Invalid parameters."}


await client.Pins.CreatePinAsync(boardid, "https://mysite.com/wp-content/uploads/images/articles/keto_recipes/wholesomeyum_fathead-pizza-crust-low-carb-keto-gluten-free-nut-free-1.jpg", "This Keto White Hen Chili is an impressive home cooking recipe for the changing seasons. It’s loading, delicious and also can conveniently be a crockpot/freezer dish! #keto #ketorecipe", "https://mysite.com/keto-white-chicken-chili-hey-keto-mom/");

{"Invalid parameters."}

Can you please see what is wrong?

Thanks, Glenn

Invalid Parameters

I have been using your wonderful library for months now with no problems. But now every time I call the function below, PinSharp throws and "Invalid Parameters" Exception. What is wrong?

await pinSharpClient.Pins.CreatePinAsync()

Here are the values I'm passing to it...

BoardID = "469289292360076140"

Image = "https://www.selfdefensegearco.com//Images/CuttingEdgeProducts/large_1592_SWM2BKspark_P.jpg"

Description = "Just recently females have actually been motivated to stand and speak up versus unwanted sexual advances and abuse. The #MeToo motion - which initially started in 2006 - has actually contributed in leading the charge in this location. Given that 1990 - nevertheless - Streetwise Security Products has actually likewise been leading the charge by manu ... #selfdefenseforwomen #selfdefenseweaponsforwomen #selfdefensetoolsforwomen #bestselfdefenseforwomen #selfdefenseitemsforwomen #selfdefensetechniquesforwomen #bestgunforwomensselfdefense #selfdefenseequipmentforwomen #selfdefensestepsforwomen #selfdefensegunsforwomen #selfdefensetacticsforwomen #basicselfdefenseforwomen #bestselfdefensepistolforwomen #selfdefenseforwomenmagazine #selfdefenseforwomenrunners"

Pin Link: "https://www.selfdefensegearco.com/StreetwiseMeToo23MillionVoltStunGun.htm"

403 error after 45+ GetPinsAsync

My issue does not directly concern a method of this project.
This is my code for download my board that contains 3000 pins:

var pins = await client.Boards.GetPinsAsync(boardName);
using (var wc = new WebClient())
{
    do
    {
        foreach (var pin in pins)
        {
            var fileName = new Uri(pin.Images.Original.Url).Segments.Last();
            var extension = new FileInfo(fileName).Extension;
            var tempFile = Path.Combine(dir.FullName, pin.Id + extension + ".tmp");
            var destination = Path.Combine(dir.FullName, pin.Id + extension);
            if (File.Exists(tempFile))
                File.Delete(tempFile);
            if (!File.Exists(destination))
            {
                wc.DownloadFile(pin.Images.Original.Url, tempFile);
                File.Move(tempFile, destination);
            }
        }
        pins = await client.Boards.GetPinsAsync(boardName, pins.NextPageCursor);
    } while (pins.Any());
}

Work fine until: wc.DownloadFile(pin.Images.Original.Url, tempFile) throw 403 Exception in loop.

Any ideas why pinterest want to block it ? Why only ~1100 pins maximum ?

Question: Pinning limits

Hi,

awesome job on the library. I was able to pin stuff very quickly.

I'd like to automatically pin certain blog posts every day. The maximum number of daily pins would be 10. Do you, by any chance, have an idea if this is agains TOS? Don't want to get banned.

Create pin from local file

Is it possible to create a new pin from a local file?
In the examples the only option is using an URL.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.