问题
While trying to send post via the Share API using the code as follows. I am getting
Internal service error status 500
PHP code
$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);
Where function has:
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;
}
The error I am getting is as given below.
$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 states that it is a server issue from LinkedIn. So should I wait for a day and then check again?
回答1:
I had the same problem when testing the LinkedIn API. Try to use another website as <submitted-url></submitted-url>.
I have also used 'http://www.google.com' and get 500 Internal service error. I changed that to 'http://www.yahoo.com', and it worked fine. I don't know exactly why that happens.
来源:https://stackoverflow.com/questions/26100042/internal-service-error-on-linkedin-using-the-share-api