Public Java/Kotlin SDK for Pinterest's new API.
<dependency>
<groupId>com.chrisdempewolf</groupId>
<artifactId>pinterest-sdk</artifactId>
<version>4.1.0</version>
</dependency>Or check Maven Central for a list of published artifacts.
This project uses Semantic Versioning; MAJOR.MINOR.PATCH: X.Y.Z, such that X, Y, and Z are natural numbers where an update to X indicates a breaking (API) change, to Y indicates new, backwards-compatible features were added, and to Z indicates a bug was patched. Please see the Semantic Versioning website for more information.
The word "Board" on Pinterest can be somewhat confusing - does it refer to <username/board_name> or just the latter, board_name part?
Here, when I say "board", I mean the <username/board_name> combination. I will say "board name" when I'm specifically refering to the name of the Board without the prepended username portion. I believe this is the approach Pinterest takes as well.
- Construct a new Pinterest SDK:
final Pinterest pinterest = new Pinterest("<INSERT_YOUR_PINTEREST_ACCESS_TOKEN>");.withCounts().withLink().withMetadata().withNote().withURL().withColor().withAttribution().withCreatedAt()
- To get a Pin (with all fields) via a Pin ID:
- Example Pin ID:
525091637782793357; from URL:https://www.pinterest.com/pin/525091637782793357/
- Example Pin ID:
final PinResponse pin = pinterest.getPin("<PIN_ID>", new PinFields().withAll());- To get a Pin with only default fields (
url,note,link,id) set:
final PinResponse pin = pinterest.getPin("<PIN_ID>");- To get a Pin with only
link,created_at, andcolorset:
final PinResponse pin = pinterest.getPin("<PIN_ID>", new PinFields().withLink().withCreatedAt().withColor());- To get your own Pins (with all fields):
final Pins pins = pinterest.getMyPins(new PinFields().withAll());
pins.forEach(pin -> {System.out.println(pin);});- To get all the Pins from a board with default fields:
- Example Board:
cdatarank/欲しいもの; from URL:https://www.pinterest.com/cdatarank/欲しいもの/
- Example Board:
final Pins pins = pinterest.getPinsFromBoard("<BOARD>");- To get all the Pins from a board with all fields:
final Pins pins = pinterest.getPinsFromBoard("<BOARD>", new PinFields().withAll());- Paging through Pin responses:
Pins pins = pinterest.getPinsFromBoard(BOARD);
while (pins.getNextPage() != null) {
pins = pinterest.getNextPageOfPins(pins.getNextPage());
}List of parameters:
| Field | Required | Description |
|---|---|---|
| Pin ID | Yes | ID of Pin to update |
| Board | No | Board to post to |
| Note | No | Pin's "note" or "description" |
| Link | No | The URL to the the Pin |
(See the Pinterest API documentation for more info).
final ResponseMessageAndStatusCode response = pinterest.patchPin("<PIN_ID>",
"(optional)<BOARD>",
"(optional)<NOTE>",
"(optional)<LINK>");- To update a Pin's note:
final ResponseMessageAndStatusCode response = pinterest.patchPin("<PIN_ID>", null, "<NOTE>", null);Currently, only POSTing via an image URL is supported. Multi-part form and base64 encoded image uploading will be added soon.
final ResponseMessageAndStatusCode response = pinterest.postPin("<BOARD>", "<NOTE>", "<IMG_URL>", "<LINK>");All you need is the Pin ID and an access token with write access to the Pin question.
This method returns true if the Pin was successfully deleted; false otherwise. This true/false return pattern was adopted from RestFB.
final boolean deleted = pinterest.deletePin("<PIN_ID>");.withCounts().withCreatedAt().withDescription().withID().withImage().withName().withURL()
- To get info about a particular Board with default fields:
- Example Board:
cdatarank/欲しいものfrom URL:https://www.pinterest.com/cdatarank/欲しいもの/
final BoardResponse boardResponse = pinterest.getBoard("<BOARD>");
final Board board = boardResponse.getBoard();- To get info about a particular Board with all fields:
final BoardResponse boardResponse = pinterest.getBoard("<BOARD>", new BoardFields().withAll());
final Board board = boardResponse.getBoard();- Paging through Board responses:
Boards boards = pinterest.getMyBoards(new BoardFields().withAll());
while (boards.getNextPage() != null) {
boards = pinterest.getNextPageOfBoards(boards.getNextPage());
}Note: this method requires a Board name not a Board (see terminology section for more information).
final String boardName = "foo";
final ResponseMessageAndStatusCode response = pinterest.postBoard(boardName, "<BOARD_DESCRIPTION>");final name = "newname"; // the _actual_ name of the board
final board = "<CURRENT_BOARD>";
final ResponseMessageAndStatusCode response = pinterest.patchBoard(board, name, description);final Boolean deleted = pinterest.deleteBoard("<BOARD>");
assertEquals(true, deleted);Note: user methods only work with the authenticated user (i.e., the owner of the access token you used to initialize the Pinterest SDK).
.withBio().withCounts().withCretedAt().withFirstName().withImage().withLastName().withURL().withUsername()
- To get a user with the default fields:
final User user = pinterest.getUser();- To get a user with all fields:
final User user = pinterest.getUser(new UserFields().withAll());- To get a user with first name and last name:
final User user = pinterest.getUser(new UserFields().withFirstName().withLastName());- To get the user's list of suggested Boards (with default fields):
final Boards boards = pinterest.getUserSuggestedBoards();- This method takes an optional
BoardFieldsparameter (see the Board section above for more info).
final Boards boards = pinterest.getUserSuggestedBoards(new BoardFields().withName());- Retrieving all of a user's Boards works the same way:
final Boards boards = pinterest.getUserBoards(new BoardFields().withName());- Paging works the same for all
Boardsresponses, so:
Boards boards = pinterest.getUserBoards(new BoardFields().withName());
while (boards.getNextPage() != null) {
boards = pinterest.getNextPageOfBoards(boards.getNextPage());
}- Similarly, to retrieve a user's Pins:
final Pins pins = pinterest.getUserPins();- Or...
final Pins pins = pinterest.getUserPins(new PinFields().withCreatedAt());- With default fields:
final Pins pins = pinterest.searchUserPins("cucumber");- With select fields:
final Pins pins = pinterest.searchUserPins("cucumber", new PinFields().withNote());- Paging works the same for all
Pinsresponses, so:
Pins pins = pinterest.searchUserPins("cucumber", new PinFields().withNote());
while (pins.getNextPage() != null) {
pins = pinterest.getNextPageOfPins(pins.getNextPage());
}- With default fields:
final Users users = pinterest.getFollowers();- With select fields:
final Users users = pinterest.getFollowers(new UserFields().withCounts().withBio());- Paginating:
Users users = pinterest.getFollowers(new UserFields().withCounts().withBio());
while (users.getNextPage() != null) {
users = pinterest.getNextPageOfUsers(users.getNextPage());
}- With default fields:
final Boards boards = pinterest.getFollowersBoards();;- With select fields:
final Boards boards = pinterest.getFollowersBoards(new BoardFields().withName().withURL());- Paginating:
Boards boards = pinterest.getFollowersBoards(new BoardFields().withName().withURL());
while (boards.getNextPage() != null) {
boards = pinterest.getNextPageOfBoards(boards.getNextPage());
}- With default fields:
final Users users = pinterest.getFollowing();- With select fields:
final Users users = pinterest.getFollowing(new UserFields().withCounts().withBio());- Paginating:
Users users = pinterest.getFollowing(new UserFields().withCounts().withBio());
while (users.getNextPage() != null) {
users = pinterest.getNextPageOfUsers(users.getNextPage());
}- With default fields:
final Boards boards = pinterest.searchUserBoards("cucumber");- With select fields:
final Boards boards = pinterest.searchUserBoards("cucumber", new BoardFields().withName());- Paging works the same for all
Boardsresponses, so:
Boards boards = pinterest.searchUserBoards("cucumber", new BoardFields().withName());
while (boards.getNextPage() != null) {
boards = pinterest.getNextPageOfBoards(boards.getNextPage());
}final ResponseMessageAndStatusCode resp = pinterest.followBoard("cdatarank/my-board");
assertEquals(200L, resp.getStatusCode());final ResponseMessageAndStatusCode resp = pinterest.followUser("cdatarank");
if (resp.getStatusCode() != 200) {
System.err.println(resp.getMessage());
}final boolean unfollowed = pinterest.unfollowBoard("cdatarank/my-board");final boolean unfollowed = pinterest.unfollowUser("cdatarank");- GET
/v1/pins/<pin_id> - GET
/v1/me/pins/<pin_id> - GET
/v1/boards/<board_name>/pins/ - GET
/v1/me/boards/ - DELETE
/v1/pins/<pin_id> - POST
/v1/pins/(still missing multi-part form uploading and base64 encoded image URLs). - POST
/v1/boards/ - PATCH
/v1/pins/<pin_id> - PATCH
/v1/boards/<board_name> - DELETE
/v1/boards/<board_name> - GET
/v1/me/ - GET
/v1/me/boards/suggested/ - GET
/v1/me/boards/ - GET
/v1/me/pins/ - GET
/v1/me/search/boards/ - GET
/v1/me/search/pins/ - GET
/v1/me/followers/ - GET
/v1/me/following/boards/ - GET
/v1/me/following/interests/ - GET
/v1/me/following/users/ - POST
/v1/me/following/boards/ - POST
/v1/me/following/users/ - DELETE
/v1/me/following/boards/<board>/ - DELETE
/v1/me/following/users/<user>/
See CONTRIBUTING.md.