pulling my hair our with this bigcommerce Auth callback (part of the new API). I have tried both regular PHP API and the latest branch found here https://github.com/maetl/bigcommerce-api-php/tree/f43e652c71550f9074dbf696c740b30651110051 which is suppose to support OAUTH.

I am using the demo code here https://developer.bigcommerce.com/apps/callback under php to begin. I have setup my app correctly etc however my php is erroring without that.The below onwards is using the OAUTH branch linked as the original has functions this code attempts to call which don't exist.

Here is my code...

<?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;
?>

This moans about the 'get' on the last 3 parts of the array first with an error like this...

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

To remove those i manually added these...

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

With these changes I get the following errors.

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

The above reference to handleReponse() which seems to be issues with the CURL operations in the library. It also refers to cipher list which has been a previous problem which requires

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

I can attach the correct classes here to get them to be picked up though I doesn't seem to set the cipher for this part as it continues to moan.

Has anyone else had a further luck on the above or have other ideas?

有帮助吗?

解决方案

Ended up using CURL to achieve this, rather than make it more difficult that it needs to be with the API.

Like below...

$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'};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top