I’m using PECL OAuth with LinkedIn because it is working fine with Twitter and LinkedIn’s GET requests. Will switch to LinkedIn’s own OAuth libraries if this fails to work, but would prefer to do everything through the same OAuth library.
Code:
$xmlString = "<?xml version='1.0' encoding='UTF-8'?>".
"<mailbox-item>".
"<recipients>".
"<recipient>".
"<person path=\"/people/email={$person->PersonEmail}\">".
"<first-name>{$person->PersonFirstName}</first-name>".
"<last-name>{$person->PersonLastName}</last-name>".
"</person>".
"</recipient>".
"</recipients>".
"<subject>Invitation to Connect</subject>".
"<body>Please join my professional network on LinkedIn.</body>".
"<item-content>".
"<invitation-request>".
"<connect-type>friend</connect-type>".
"</invitation-request>".
"</item-content>".
"</mailbox-item>";
try {
$oauth = new OAuth(self::$apiKey, self::$secretKey, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_FORM);
$oauth->setToken($accessToken, $accessTokenSecret);
$oauth->fetch("http://api.linkedin.com/v1/people/~/mailbox", $xmlString, OAUTH_HTTP_METHOD_POST, array('Content-Type'=>'text/xml'));
$result = $oauth->getLastResponse();
return $result;
} catch (OAuthException $e) {
var_dump($e);
throw new ModelException('Error - Invalid Access Token', ModelException::$excodes['invalid_access_token']);
}
This throws an exception which is caught, and the var_dump spits out a lot, primarily: “Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)”
I’ve tried a number of variations with the code. For example dropping the ‘Content-Type’=>’text/xml’ and that gives the same error. I’ve validated the xml and I know the access tokens are good, as I’m using them just fine to make GET requests.
Any help would be appreciated, thanks.
Found the solution, it was replacing
with