2015-04-16 13 views
6

मैं उपयोगकर्ता समयरेखा के अपडेट पोस्ट करने के लिए LinkedIn REST API का उपयोग कर रहा हूं। कुछ दिनों से मुझे LinkedIn से Internal server error प्रतिक्रिया मिलती है लेकिन कोड पहले काम करता था।लिंक्डइन आरईएसटी एपीआई - आंतरिक सर्वर त्रुटि

पीएचपी:

$postTitle = "hello"; 
$postDesc = "world "; 
$submitted-url = "http://example.com"; 
$submitted-image-url = "http://images.example.com/img/hello.jpg"; 
$comment = "foobar"; 

$postData = array('visibility' => array('code' => 'connections-only'), 
'content' => array('title' => $postTitle,'description' => $postDesc,'submitted-url' => $postURL,'submitted-image-url' => $postImage), 'comment' => $postComment); 

$ch = curl_init('https://api.linkedin.com/v1/people/~/shares?oauth2_access_token='.$oauthToken.'&format=json' 
); 

curl_setopt_array($ch, array(
CURLOPT_POST => TRUE, 
CURLOPT_RETURNTRANSFER => TRUE, 
CURLOPT_HTTPHEADER => array('x-li-format: json', "Content-Type: application/json"), 
CURLOPT_POSTFIELDS => json_encode($postData) 
)); 

$response = curl_exec($ch); 

कैसे है कि त्रुटि को ठीक?

उत्तर

4

आपका कोड अमान्य PHP है (शायद पोस्ट करने से पहले किए गए कुछ संपादनों के कारण?); करने के लिए इसे संशोधित:

$postTitle = "hello"; 
$postDesc = "world "; 
$postURL = "http://example.com"; 
$postImage = "http://images.example.com/img/hello.jpg"; 
$postComment = "foobar"; 

$oauthToken = "<token>"; 

$postData = array(
    'visibility' => array('code' => 'connections-only'), 
    'content' => array(
     'title' => $postTitle, 
     'description' => $postDesc, 
     'submitted-url' => $postURL, 
     'submitted-image-url' => $postImage 
    ), 
    'comment' => $postComment 
); 

$ch = curl_init('https://api.linkedin.com/v1/people/~/shares?oauth2_access_token='.$oauthToken.'&format=json'); 

curl_setopt_array($ch, array(
    CURLOPT_POST => TRUE, 
    CURLOPT_RETURNTRANSFER => TRUE, 
    CURLOPT_HTTPHEADER => array('x-li-format: json', "Content-Type: application/json"), 
    CURLOPT_POSTFIELDS => json_encode($postData) 
)); 

$response = curl_exec($ch); 

काम करता है अगर केवल $oauthToken एक मान्य टोकन को तैयार है। मान लें कि आपका असली कोड सही है, केवल एक ही संभावना है कि आपका ओथ टोकन समाप्त हो गया है और आपको पहले एक नया प्राप्त करने की आवश्यकता है। कर्ल विकल्पों में CURLOPT_VERBOSE => TRUE जोड़कर आप लिंकडइन रिटर्न की त्रुटि के बारे में अधिक जानकारी प्राप्त करेंगे।

+0

बस एक मान्य टोकन के माध्यम से अपने कोड की कोशिश की और एक ही "आंतरिक सेवा त्रुटि" हो गया है: 'प्रतिक्रिया: {" errorCode ": 0," message ":" आंतरिक सेवा त्रुटि "," requestId ":" J6PAQ9 "," स्थिति ": 500," टाइमस्टैम्प ": 1429742} 'कोई विचार? – Tom

2

आप लिंक्डइन पीएचपी एसडीके (समुदाय द्वारा प्रदान की) का उपयोग पर विचार कर सकते हैं बजाय: https://github.com/Happyr/LinkedIn-API-client

+0

क्या लिंक्डइन एपीआई के लिए मुझे कोई सीमा है, मुझे इसके बारे में पता होना चाहिए? (टाइमआउट, छवि यूआरएल के लिए अधिकतम आकार ...) – Tom

1

हम वही समस्या Linkedin एपीआई के साथ हाल ही में सामना करना पड़ा। अंत में यूआरएल को बदलकर फिक्स को समझ लिया।

नया URL: "https://api.linkedin.com/v1/people/~/shares"

इसके बजाय क्वेरी स्ट्रिंग में निर्दिष्ट करने 'oauth2_access_token' की

, यह शीर्षक में जोड़ने - निर्दिष्ट करें:

"प्राधिकरण", "वाहक" + accessToken।

और अंत में अनुरोध शरीर पैरामीटर में, अपने JSON/XML डेटा जोड़ने

1

आप अनुरोध हेडर में अपने प्रमाणीकरण टोकन का प्रयोग करने के लिए है पोस्ट करने के लिए।

यह कामकाजी कोड है। कोशिश करो।

$postTitle = "hello"; 
$postDesc = "world "; 
$submitted-url = "http://example.com"; 
$submitted-image-url = "http://images.example.com/img/hello.jpg"; 
$comment = "foobar"; 

$oauthToken = "TokenHere"; 


$postData = array('visibility' => array('code' => 'connections-only'), 
'content' => array('title' => $postTitle,'description' => $postDesc,'submitted-url' => $postURL,'submitted-image-url' => $postImage), 'comment' => $postComment); 

$ch = curl_init('https://api.linkedin.com/v1/people/~/shares?format=json'); 


curl_setopt_array($ch, array(
CURLOPT_POST => TRUE, 
CURLOPT_RETURNTRANSFER => TRUE, 
CURLOPT_HTTPHEADER => array('x-li-format: json', "Content-Type: application/json", "Bearer: ".$oauthToken.""), 
CURLOPT_POSTFIELDS => json_encode($postData) 
)); 

$response = curl_exec($ch); 
संबंधित मुद्दे