请求OAUTH令牌调查猴子v3时缺少参数

我试图使用CURL / PHP来获得我的“长期存取令牌”,但我收到错误“客户端id,客户端密码,代码,grant_type,redirect_uri缺少参数”。

我打电话的网址是您可以清楚地看到我想要传入的参数!

https://api.surveymonkey.net/oauth/token?client_secret='.urlencode($client_secret).'&code='.urlencode($short_token).'&redirect_uri='.urlencode($redirect_url).'&client_id=” .urlencode($ CLIENT_ID)。'&grant_type = authorization_code

我也按照文档(见下文)使用“application / x-www-form-urlencoded”的内容类型。

我的CURL请求:

function survey_monkey_curl_request($url, $params=[], $request_type = 'get', $access_token) {

  print_r($url);

  $ch = curl_init();

  $headers = [
    "Content-Type: application/x-www-form-urlencoded",
    "Authorization: bearer " .$access_token
  ];
  $opts = [
    CURLOPT_URL => $url,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_SSL_VERIFYPEER => 0,
  ];
  if ($request_type == 'post') {
    $opts[CURLOPT_POST] = 1;
    //$opts[CURLOPT_POSTFIELDS] = json_encode($params);
  }
  if ($request_type == 'patch') {
    $opts[CURLOPT_CUSTOMREQUEST] = "PATCH";
    $opts[CURLOPT_POSTFIELDS] = json_encode($params);
  }
  curl_setopt_array($ch, $opts);
  $result = curl_exec($ch);

  if ($result === false)  {
    curl_close($ch);
    throw new Exception(curl_error($ch));
  }
  curl_close($ch);
  return $result;
}

我哪里错了?


直接从它看起来像获得长寿命的令牌你需要发布你的领域的文档:

//Exchange for long-lived token

curl -i -X POST https://api.surveymonkey.net/oauth/token -d 
"client_secret=YOUR_CLIENT_SECRET 
&code=AUTH_CODE 
&redirect_uri=YOUR_REDIRECT_URI 
&client_id=YOUR_CLIENT_ID 
&grant_type=authorization_code"

https://developer.surveymonkey.com/api/v3/?shell#new-authentication

当你将你的参数附加到你的url时,你将以GET请求参数的形式发送

您需要将您的数据字符串放入CURL POSTFIELDS中,并且不要json编码

PHP答案

<?php

$ch = curl_init();

$data = [
    'client_secret' => $YOUR_CLIENT_SECRET,
    'code' => $AUTH_CODE,
    'redirect_url' => $YOUR_REDIRECT_URI,
    'client_id' => $YOUR_CLIENT_ID,
    'grant_type' => 'authorization_code'
];//set your data as an array

$headers = [
    "Content-Type: application/x-www-form-urlencoded",
    "Authorization: bearer " . $access_token
];
$opts = [
    CURLOPT_URL => $url,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_SSL_VERIFYPEER => 0,
];
if ($request_type == 'post') {
    $opts[CURLOPT_POST] = 1;
    $opts[CURLOPT_POSTFIELDS] = http_build_query($data);// this will build your data string from the array
}

curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
curl_close($ch);
return $result;
链接地址: http://www.djcxy.com/p/68439.html

上一篇: Missing parameters when requesting OAUTH token survey monkey v3

下一篇: Salesforce OAuth 2.0 User