php [Pinterest api] Pinterest api php #social

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [Pinterest api] Pinterest api php #social相关的知识,希望对你有一定的参考价值。

<?php
/*
https://github.com/seregazhuk/php-pinterest-bot
composer require seregazhuk/pinterest-bot

https://sergeyzhuk.me/2017/03/25/build-pinterest-bot-with-php-auto-pin/
*/
use seregazhuk\PinterestBot\Factories\PinterestBot;

$bot = PinterestBot::create();

// Login
$bot->auth->login('hoangsoft', 'HDpFjv5RtVN3j1dS3L4a');

/**
	Boards
*/
// Get lists of your boards
$boards = $bot->boards->forUser('hoangsoft');
$boardId = $boards[0]['id'];

//create new board
$id=$bot->boards->create('WordPressThemes', 'WordPress Themes');

//create pin
$blogUrl = 'http://awasome-blog-about-cats.com';
$keywords = ['cats', 'kittens', 'funny cats', 'cat pictures', 'cats art'];
// select image for posting
$images = glob('images/*.*');
if(empty($images)) {
    echo "No images for posting\n";
    die();
}

$image = $images[0];

// select keyword
$keyword = $keywords[array_rand($keywords)];

// create a pin? error
$bot->pins->create($image, $boardId, $keyword, $blogUrl);
<?php
//https://github.com/dirkgroenen/Pinterest-API-PHP
const CLIENT_ID='5010885921734677901';
const CLIENT_SECRET='f6bcf236a800dd4fd8130c6e8ca42f1353d32dee65fbdb42b240a6b8e5a9ff59';
const CALLBACK_URL='https://6df95814.ngrok.io';//'http://localhost/test/php/pinterest.php';

use DirkGroenen\Pinterest\Pinterest;

require('vendor/autoload.php'); 

$pinterest = new Pinterest(CLIENT_ID, CLIENT_SECRET);
//auth
if(isset($_GET["code"])){
    $token = $pinterest->auth->getOAuthToken($_GET["code"]);
    $pinterest->auth->setOAuthToken($token->access_token);
    var_dump($token->access_token);
}
else {
  $loginurl = $pinterest->auth->getLoginUrl(CALLBACK_URL, array('read_public','write_public','write_public'));
  echo '<a href=' . $loginurl . '>Authorize Pinterest</a>';
}

/*
user profile:
{
    "id": "503066358284560467",
    "username": null,
    "first_name": "Dirk ",
    "last_name": "Groenen",
    "bio": null,
    "created_at": null,
    "counts": null,
    "image": null
}
*/
//By default, not all fields are returned
$me = $pinterest->users->me();
print_r(json_decode($me));

//get more fields
$pinterest->users->me(array(
    'fields' => 'username,first_name,last_name,image[small,large]'
));

//find user
$pinterest->users->find('dirkgroenen');

/**
	Collections: pin, board
*/

//get user pins
$collects = $pinterest->users->getMePins();

//Get all items
$collects->all();

//Get item at index
$pins = $pinterest->users->getMeLikes();
$pins->get(0);
$collects->get(0);

//Get user's boards
$pinterest->users->getMeBoards();

//Get user's followers
$pinterest->users->getMeFollowers();

/**
	Rate limit
*/
//get the maximum number of requests
$pinterest->getRateLimit();

//get the remaining number of calls
$pinterest->getRateLimitRemaining();

/**
	Boards
*/
//get board
$pinterest->boards->get("<username>/pinterest-api-test");

//create board
$pinterest->boards->create(array(
    "name"          => "Test board from API",
    "description"   => "Test Board From API Test"
));

//update board
$pinterest->boards-edit("dirkgroenen/pinterest-api-test", array(
    "name"  => "Test board after edit"
));

//delete board
$pinterest->boards->delete("dirkgroenen/pinterest-api-test");

/**
	Pins: https://developers.pinterest.com/docs/api/pins/?
*/
//get pin
$pinterest->pins->get("181692166190246650");

//Get pins from board
$pinterest->pins->fromBoard("dirkgroenen/pinterest-api-test");

/*
Creating a pin with an image hosted somewhere
*/
$pinterest->pins->create(array(
    "note"          => "Test board from API",
    "image_url"     => "https://download.unsplash.com/photo-1438216983993-cdcd7dea84ce",
    "board"         => "<user>/pinterest-api-test",
  "link"=> "https://hoangweb.net?s=theme1&post_type=product"
));

//Creating a pin with an image located on the server
$pinterest->pins->create(array(
    "note"          => "Test board from API",
    "image"         => "/path/to/image.png",
    "board"         => "dirkgroenen/pinterest-api-test"
));

//Creating a pin with a base64 encoded image
$pinterest->pins->create(array(
    "note"          => "Test board from API",
    "image_base64"  => "[base64 encoded image]",
    "board"         => "dirkgroenen/pinterest-api-test"
));

/*
update pin
*/
$pinterest->pins->edit("181692166190246650", array(
    "note"  => "Updated name"
));

//delete pin
$pinterest->pins->delete("181692166190246650");

以上是关于php [Pinterest api] Pinterest api php #social的主要内容,如果未能解决你的问题,请参考以下文章

您的要求无法解决为 pinterest API 的一组可安装软件包

pinterest api文档[关闭]

php 除去-Pinterest的 - 选择 - avatar.php

php Genesis Pinterest按钮。

php Pinterest“Pin It”按钮。

php Jan Dembowski过滤the_content()以添加Pinterest按钮代码。