尝试使用以下代码通过Share API发送帖子。我正在
内部服务错误状态500
$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的服务器问题。那么我应该等一天然后再检查一下吗?
答案 0 :(得分:3)
我在测试LinkedIn API时遇到了同样的问题。尝试将其他网站用作&lt; submitted-url&gt;&lt; / submitted-url&gt ;.
我还使用了“http://www.google.com”并获得了500内部服务错误。我将其更改为“http://www.yahoo.com”,并且工作正常。我不知道为什么会发生这种情况。