I am working with linkedin API. I have followed the instructions given at https://developer.linkedin.com/docs/oauth2 - so I have got the code, exchanged that for an access token. All good.
Now when I try to hit the API, for example to post an update, "Step 4 — Make authenticated requests" I always get an error returned from the API saying my access token is invalid.
My Header Params sent to the API are this:
array(5) {
[0]=>
string(22) "Connection: Keep-Alive"
[1]=>
string(137) "Authorization: Bearer AQS888888888888888888888888888888-Ab2HY"
[2]=>
string(30) "Content-Type: application/json"
[3]=>
string(17) "x-li-format: json"
[4]=>
string(19) "Content-Length: 171"
}
The API response always gives me this:
string(134) "{
"errorCode": 0,
"message": "Invalid access token.",
"requestId": "IRBXBZ1X5V",
"status": 401,
"timestamp": 1468498680913
}"
My debug from curl_getinfo()
returns this data:
array(22) {
["url"]=>
string(29) "https://api.linkedin.com/v1/?"
["content_type"]=>
string(30) "application/json;charset=UTF-8"
["http_code"]=>
int(401)
["header_size"]=>
int(495)
["request_size"]=>
int(466)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(0)
["redirect_count"]=>
int(0)
["total_time"]=>
float(0.275796)
["namelookup_time"]=>
float(0.003589)
["connect_time"]=>
float(0.00685)
["pretransfer_time"]=>
float(0.055621)
["size_upload"]=>
float(171)
["size_download"]=>
float(134)
["speed_download"]=>
float(485)
["speed_upload"]=>
float(620)
["download_content_length"]=>
float(134)
["upload_content_length"]=>
float(171)
["starttransfer_time"]=>
float(0.275764)
["redirect_time"]=>
float(0)
["certinfo"]=>
array(0) {
}
["redirect_url"]=>
string(0) ""
}
I am posting and expecting a response in JSON rather than XML.
See https://developer.linkedin.com/docs/share-on-linkedin for the docs I am following
I am confident that the access token is correct, I suspect I am not passing it correctly in the header "Authorization: Bearer", or my endpoint URL is not quite correct, I have tried this too:
https://api.linkedin.com/v1/people/~/shares?format=json
and
https://api.linkedin.com/v2/people/~/shares?format=json
Any ideas? NOTE I have removed most of the access token here, don't ask me to publish it!