PHP - 使用Guzzle或oauth2-client的POST数组数据

时间:2016-06-09 16:52:51

标签: php laravel curl guzzle oauth2client

我需要一些帮助连接到deviantArt的API for whois。

我正在构建一个需要连接到deviantArt的API的Laravel应用程序。

我可以使用SocialiteThe League's OAuth2-ClientGuzzle和cUrl成功连接到API,但仅限于whoami请求。
GET /user/whoami

我可以成功whois连接,但只能使用cUrl POST /user/whois

curl https://www.deviantart.com/api/v1/oauth2/user/whois \
-d "usernames[0]=justgalym" \
-d access_token=Alph4num3r1ct0k3nv4lu3

我希望尽可能多地使用OAuth2-Client插件,但此时,我只是在寻找有用的东西。

我最好的猜测是我没有正确发送POST个变量。

尝试1 - 使用Guzzle请求

$options = [
  'form_params' => [
    'usernames[0]' => 'justgalym',
    'expand' => 'user.profile',
  ],
  "Authorization" => "Bearer ".$this->token->getToken()
];

$request = new Request('POST', $url, $options);

尝试2 - 使用Guzzle请求

$options = [
  'form_params' => [
    'usernames[]' => 'justgalym',
    'expand' => 'user.profile',
  ],
  "Authorization" => "Bearer ".$this->token->getToken()
];

$request = new Request('POST', $url, $options);

尝试3 - 使用Guzzle请求

$options = [
  'form_params' => [
    'usernames' => 'justgalym',
    'expand' => 'user.profile',
  ],
  "Authorization" => "Bearer ".$this->token->getToken()
];

$request = new Request('POST', $url, $options);

尝试4 - 使用Guzzle请求

$options = [
  'form_params' => [
    'usernames' => 
       [0 => 'justgalym'],
    'expand' => 'user.profile',
  ],
  "Authorization" => "Bearer ".$this->token->getToken()
];

$request = new Request('POST', $url, $options);

尝试5 - 使用Oauth-client getAuthenticatedRequest

$request = $this->provider->
           getAuthenticatedRequest(
               AbstractProvider::METHOD_POST, 
               $url, $this->token,  ['body' => 'usernames[0]=justgalym'
]);

尝试......

和其他许多人

所有尝试的结果都给出了同样的错误。

array(
  'error' => 'invalid_request', 
  'error_description' => 'Request field validation failed.', 
  'error_details' => 
    array(
      'usernames' => 'usernames is required'
    ), 
  'status' => 'error'
)

0 个答案:

没有答案