我在使用 PHP 的 PECL OAuth 模块向 LinkedIn 共享 API 发出请求时遇到问题。我已经用谷歌搜索了我的价值,但我找不到任何例子。
我的 PHP 代码:
$linkedin_oauth = new OAuth($linkedin_consumer_key,$linkedin_consumer_secret,OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_FORM);
$linkedin_oauth->setToken($linkedin_data->linkedin_token, $linkedin_data->linkedin_consumer_secret);
$linkedin_oauth->setAuthType(OAUTH_AUTH_TYPE_FORM);
$body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$body .= "<share>";
$body .= "<comment>83% of employers will use social media to hire: 78% LinkedIn, 55% Facebook, 45% Twitter [SF Biz Times] http://bit.ly/cCpeOD</comment>";
$body .= "<content>";
$body .= "<title>Survey: Social networks top hiring tool - San Francisco Business Times</title>";
$body .= "<submitted-url>http://sanfrancisco.bizjournals.com/sanfrancisco/stories/2010/06/28/daily34.html</submitted-url>";
$body .= "<submitted-image-url>http://images.bizjournals.com/travel/cityscapes/thumbs/sm_sanfrancisco.jpg</submitted-image-url>";
$body .= "</content>";
$body .= "<visibility>";
$body .= "<code>anyone</code>";
$body .= "</visibility>";
$body .= "</share>";
$headers = array('Content-Type' => 'text/xml');
$linkedin_oauth->fetch("http://api.linkedin.com/v1/people/~/shares", $body, OAUTH_HTTP_METHOD_POST, $headers);
$linkedin_share_response = $linkedin_oauth->getLastResponse();
但这会导致异常:
Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)
我的标题看起来像:
OAuth oauth_consumer_key="<KEY_REMOVED>",oauth_signature_method="HMAC-SHA1",oauth_nonce="12581672284fa32618a44a31.27944550",oauth_timestamp="1336092184",oauth_version="1.0",oauth_token="<TOKEN_REMOVED>",oauth_signature="Qqt5zQKITSvk7OyrdWdFLaR%2F9ns%3D
有谁知道这里发生了什么?无论我做什么,响应始终是 401。
当我用 GET 调用替换 call 时,它工作正常。