Shutterstock - 灯箱 - 缺少必需的范围错误
Shutterstock - lightboxes - Missing required scope error
我正在尝试从 shutterstock 获取我的灯箱图片集。我正在使用 php(wordpress 网站)。为此,我遵循了文档中的示例,但为我的应用程序应用了代码。
要获取令牌,我使用此代码:
$client_id = 'My CLIENT ID here.';
$client_secret = 'My client secret there';
$redirect_uri = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . "{$_SERVER['HTTP_HOST']}" . strtok($_SERVER['REQUEST_URI'], '?');
if(isset($_GET['code'])) {
$url = 'https://accounts.shutterstock.com/oauth/access_token';
$params = array(
code => $_GET['code'],
scope => 'collections.view',
client_id => $client_id,
client_secret => $client_secret,
redirect_uri => $redirect_uri,
grant_type => 'authorization_code'
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response);
if (json_last_error()) {
echo '<span style="font-weight:bold;color:red;">Error: ' . $response . '</span>';
} else {
$_SESSION['access_token'] = $json->access_token;
}
之后我使用此代码获取灯箱:
...
$url = 'https://api.shutterstock.com/v2/images/collections/33162025/items';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $this->accessToken));
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response);
但是,我收到此错误,而不是请求灯箱信息:
缺少必需的范围:collections.view
如您所见,我的参数数组中有范围参数。我在那里错过了什么?
您在获得授权后通过了范围,这是不正确的。
请求访问令牌时传递范围,请参见下面的案例。
只需替换您的凭据并将 url 复制到浏览器,它肯定会起作用。
干杯 :)
我正在尝试从 shutterstock 获取我的灯箱图片集。我正在使用 php(wordpress 网站)。为此,我遵循了文档中的示例,但为我的应用程序应用了代码。
要获取令牌,我使用此代码:
$client_id = 'My CLIENT ID here.';
$client_secret = 'My client secret there';
$redirect_uri = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . "{$_SERVER['HTTP_HOST']}" . strtok($_SERVER['REQUEST_URI'], '?');
if(isset($_GET['code'])) {
$url = 'https://accounts.shutterstock.com/oauth/access_token';
$params = array(
code => $_GET['code'],
scope => 'collections.view',
client_id => $client_id,
client_secret => $client_secret,
redirect_uri => $redirect_uri,
grant_type => 'authorization_code'
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response);
if (json_last_error()) {
echo '<span style="font-weight:bold;color:red;">Error: ' . $response . '</span>';
} else {
$_SESSION['access_token'] = $json->access_token;
}
之后我使用此代码获取灯箱:
...
$url = 'https://api.shutterstock.com/v2/images/collections/33162025/items';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $this->accessToken));
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response);
但是,我收到此错误,而不是请求灯箱信息:
缺少必需的范围:collections.view
如您所见,我的参数数组中有范围参数。我在那里错过了什么?
您在获得授权后通过了范围,这是不正确的。
请求访问令牌时传递范围,请参见下面的案例。
只需替换您的凭据并将 url 复制到浏览器,它肯定会起作用。 干杯 :)