【发布时间】:2015-01-11 00:15:37
【问题描述】:
尝试通过Share API 发送帖子时,使用如下代码。我得到了
内部服务错误状态500
PHP 代码
$base_url = 'https://api.linkedin.com/v1/people/~/';
$url = $base_url . 'shares';
$xml = '<share>';
$xml .= '<comment>' . 'test'. '</comment>';
$xml .= '<content>';
$xml .= '<title>' . 'TEST' . '</title>';
$xml .= '<submitted-url>' . 'http://www.google.com' . '</submitted-url>';
$xml .= '<description>' . 'description' . '</description>';
$xml .= '</content>';
$xml .= '<visibility><code>anyone</code></visibility>';
$xml .= '</share>';
$signature = new OAuthSignatureMethod_HMAC_SHA1();
$consumer_key = '';$consumer_secret = '';
$consumer = new OAuthConsumer('my_api_key', 'my_api_secret_key', NULL);
$token = new OAuthConsumer( $oauth['oauth_token'], $oauth['oauth_token_secret'], 1);
$request = OAuthRequest::from_consumer_and_token($consumer, $token, 'POST', $url, array ());
$request->sign_request($signature, $consumer, $token);
$header = $request->to_header();
$response = _linkedin_http_request($url, $header, $xml);
函数有:
function _linkedin_http_request($url, $header, $body = NULL) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
curl_setopt($ch, CURLOPT_URL, $url);
if ($body) {
curl_setopt($ch, CURLOPT_POST, 1);
if ($body == 'token_request') {
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
}
else {
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($header, 'Content-Type: text/xml;charset=utf-8'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
}
}
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
我得到的错误如下所示。
$response = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
<status>500</status>
<timestamp>1411993375587</timestamp>
<request-id>FYVRCIMJYO</request-id>
<error-code>0</error-code>
<message>Internal service error</message>
</error>
Handling Errors & Invalid Tokens 声明这是来自 LinkedIn 的服务器问题。那我是不是应该等一天再检查一下?
【问题讨论】:
-
这个问题似乎离题了,因为它与编程无关,而只是 LinkedIn API 的问题。
-
回复:重新打开 - 请参阅 Brad Larson's answer。
标签: linkedin