【问题标题】:Stuck with PHP Square API - AUTHENTICATION_ERROR使用 PHP Square API - AUTHENTICATION_ERROR
【发布时间】:2017-12-02 01:49:38
【问题描述】:

我想将 Square API 用于项目,以便在现有 Square POI 中推送生成的订单。

为此,我需要使用 Checkout API 和我在 square 开发门户上生成的个人应用访问令牌,但它一直告诉我我没有足够的权限执行此操作!

API 答案

API 调用

方形文档

感谢您的帮助:)

【问题讨论】:

  • 放一个“!”使用您的链接![Text][1]![Text](Url) 以显示图片
  • 我没有看到您的请求中设置了标头 Authorization 和 Content-Type。请设置它们
  • 你能分享 Postman 中的标题部分吗?另请注意,Square 有一个预制的 Postman 集合,可能对您来说更容易。 medium.com/square-corner-blog/…
  • 很遗憾我没有足够的声望来嵌入图片!

标签: php curl square square-connect


【解决方案1】:

感谢您的回答!

即使使用官方邮递员,错误似乎再次发生:(

Postman header

我刚刚在 Postman 中添加了 location_id 和 token 变量,响应又是 403 错误。 我使用官方 Square 连接库的 PHP 脚本也是如此。

SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken('sq0atp-TOKEN');
$api_instance2 = new SquareConnect\Api\OrdersApi(); 
$body = new \SquareConnect\Model\CreateOrderRequest();      
$itemstobuy = array(array("catalog_object_id" => "FYFGTSEZBVFP3BYECIJOCYAC", "quantity" => "1"), array("catalog_object_id" => "TMIQXB7RZY4EPXQZZAO3QVYM", "quantity" => "1"));  

$body->setIdempotencyKey(uniqid());
$body->setLineItems($itemstobuy);
$body->setReferenceId("Test".uniqid());   


try {          
   $api_instance = new SquareConnect\Api\CheckoutApi();     
   $checkout = new \SquareConnect\Model\CreateCheckoutRequest();   
    $checkout->setOrder($body);     
   $checkout->setIdempotencyKey("Test_".uniqid()); 

    try {         
       $result = $api_instance->createCheckout($location_id, $checkout);         

     } catch (Exception $e) {            
        echo "The SquareConnect\Configuration object threw an exception while " .        "calling CheckoutApi->createCheckout: ", $e->getMessage(), PHP_EOL;   exit; }       

} catch (Exception $e) {    
      echo 'Exception when calling OrdersApi->createOrder: ', $e->getMessage(), PHP_EOL; 

}

【讨论】:

    猜你喜欢
    • 2016-10-10
    • 2017-10-11
    • 1970-01-01
    • 2022-08-20
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多