gatioo / yotpo
YOTPO API的PHP接口,包含少量修复
0.0.1
2013-05-27 18:30 UTC
Requires
- php: >=5.3.2
- nategood/httpful: *
Requires (Dev)
- phpunit/phpunit: 3.7.*@dev
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2024-09-20 19:40:21 UTC
README
YOTPO API的PHP接口
需求
- YOTPO API需要PHP 5.3.0(或更高版本)。
安装
首先克隆存储库
git clone git@github.com:YotpoLtd/yotpo-php.git
然后下载并安装composer依赖项
php -r "eval('?>'.file_get_contents('https://getcomposer.org.cn/installer'));"
php composer.phar install
用法
首先 在Yotpo注册您的应用程序 然后复制并粘贴app_key和secret
include "yotpo-php/bootstrap.php"; $ak = "APP_KEY"; $st = "SECRET"; $yotpo = new \Yotpo\Yotpo($ak, $st);
这就完成了,您已经准备好了。
现在让我们对我们的API进行一些公开调用。公开调用只需要您使用有效的app_key。
使用API创建第一个评论
$yotpo->create_review(array( 'app_key' => $ak, 'product_id' => "BLABLA", 'shop_domain' => "omri.co", 'product_title' => "pt", 'product_description' => "pd", 'product_url' => "http://google.com/?q=myproducturl", 'product_image_url' => "https://www.google.com/images/srpr/logo4w.png", 'user_display_name' => "MOSHE5656", 'user_email' => 'haim@yotpo.com', 'review_body' => "this is my review body", 'review_title' => "my review title" , 'review_score' => 5 ));
现在让我们检索我们的产品BLABLA的所有评论
$response = $yotpo->get_product_reviews(array('app_key' => $ak, 'product_id' => "BLABLA")); echo $response->response->reviews[0]->title; echo $response->response->reviews[0]->score;
获取产品BLABLA的总结
$response = $yotpo->get_product_bottom_line(array('app_key' => $ak, 'product_id' => "BLABLA")); echo $response->response->bottomline->average_score; echo $response->response->bottomline->total_reviews;
现在让我们尝试一些稍微复杂一点的事情。让我们尝试创建一个购买。
为此,我们需要完成Yotpo认证流程,提供app_key和secret,然后返回以获取utoken。utoken将允许我们进行认证的API调用。
// retrieving the utoken - will be valid for 24 hours $credentials = $yotpo->get_oauth_token(); $utoken = $credentials->access_token; // first creating the products that are in the order, notice that the key of the product hash is the product_sku $products = array( "BLABLA1" => array( 'url' => "http://shop.yotpo.com/products/amazing-yotpo-poster", 'name' => "Yotpo Amazing Poster", 'image_url' => "http://cdn.shopify.com/s/files/1/0098/1912/products/qa2_medium.png?41", 'description' => "this is the most awesome poster in the world!", 'price' => "100" ) ); //now we will create a purchase using this the token we have received in the previous step $response = $yotpo->create_purchase(array( 'app_key' => $ak, 'utoken' => $utoken, 'email' => "trial@yotpo.com", 'customer_name' => "bob", 'order_id' => "13444", 'platform' => "Shopify", 'order_date' => "2013-05-28", 'products' => $products, 'currency_iso' => "USD" ));
我们可以拉取某个账户的所有购买,以确保前面的调用已成功
$response = $yotpo->get_purchases(array('app_key' => $ak, 'utoken' => $utoken, 'since_date' => "2013-05-26")); echo $response->response->total_purchases;
贡献
- 分支
- 创建您的功能分支(
git checkout -b my-new-feature
) - 提交您的更改(
git commit -am 'Add some feature'
) - 推送到分支(
git push origin my-new-feature
) - 创建新的Pull Request