Bigcommerce Auth Callback / w PHP API

时间:2014-03-02 01:11:21

标签: php curl bigcommerce

通过这个大商业Auth回调(新API的一部分)拉我的头发。 我已经尝试了常规PHP API和这里找到的最新分支https://github.com/maetl/bigcommerce-api-php/tree/f43e652c71550f9074dbf696c740b30651110051,它可以支持OAUTH。

我正在使用php下的演示代码https://developer.bigcommerce.com/apps/callback开始。我已正确设置我的应用程序等,但是我的php没有错误。下面的内容是使用OAUTH分支链接,因为原始代码试图调用哪些函数不存在。

这是我的代码......

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

include $_SERVER['DOCUMENT_ROOT'] . '/libraries/bigcommerce/bigcommerce.php';

use Bigcommerce\Api\Connection;

$tokenUrl = "https://login.bigcommerce.com/oauth2/token";
$connection = new Connection();
$connection->useUrlencoded();
$response = $connection->post($tokenUrl, array(
    "client_id" => "#myid",
    "client_secret" => "#mysecret",
    "redirect_url" => "http://#myoauthurl",
    "grant_type" => "authorization_code",
    "code" => $request->get("code"),
    "scope" => $request->get("scope"),
    "context" => $request->get("context"),
));

$token = $response->access_token;
?>

这首先对阵列的最后3个部分的'get'抱怨,并出现这样的错误......

Notice: Undefined variable: request in /var/www/integrations/bigcommerce/oauth2.php on line 18 Fatal error: Call to a member function get() on a non-object in /var/www/integrations/bigcommerce/oauth2.php on line 18

要删除那些我手动添加这些......

"code" => $_GET["code"],
"scope" => $_GET["scope"],
"context" => $_GET["context"],

通过这些更改,我收到以下错误。

Fatal error: Uncaught exception 'Bigcommerce\Api\NetworkError' with message 'failed setting cipher list' in /var/www/libraries/bigcommerce/bigcommerce.php:95 Stack trace: #0 /var/www/libraries/bigcommerce/bigcommerce.php(169): Bigcommerce\Api\Connection->handleResponse() #1 /var/www/integrations/bigcommerce/oauth.php(21): Bigcommerce\Api\Connection->post('https://login.b...', Array) #2 {main} thrown in /var/www/libraries/bigcommerce/bigcommerce.php on line 95

上面对handleReponse()的引用似乎与库中的CURL操作有关。 它还指密码列表,这是以前需要的问题

Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);

我可以在这里附上正确的类来让它们被拾取,虽然我似乎没有设置这个部分的密码,因为它继续呻吟。

还有其他人对上述情况有进一步的运气还是有其他想法?

1 个答案:

答案 0 :(得分:4)

结束使用CURL实现这一目标,而不是让它更难以与API一起使用。

如下所示......

$data = array(
    "client_id" => "",
    "client_secret" => "",
    "redirect_uri" => "http://",
    "grant_type" => "authorization_code",
    "code" => $_GET["code"],
    "scope" => $_GET["scope"],
    "context" => $_GET["context"],
);
$postfields = http_build_query($data);

$ch = curl_init();                    
$url = "https://login.bigcommerce.com/oauth2/token";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);

$obj = json_decode($output);
$access_token = $obj->{'access_token'};
$scope = $obj->{'scope'};
$id =  $obj->{'user'}->{'id'};
$email =  $obj->{'user'}->{'email'};
$context = $obj->{'context'};