使用 PECL OAuth 通过 PHP 的 REST API 发出 LinkedIn 邀请请求的错误
我将 PECL OAuth 与 LinkedIn 一起使用,因为它可以很好地处理 Twitter 和 LinkedIn 的 GET 请求。如果这不起作用,将切换到 LinkedIn 自己的 OAuth 库,但更愿意通过相同的 OAuth 库完成所有操作。
代码:
$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']);
}
这会引发一个被捕获的异常,并且 var_dump 会吐出很多内容,主要是:“无效的身份验证/错误请求(收到 401,预期 HTTP/1.1 20X 或重定向)”
我尝试了多种变体代码。例如,删除 'Content-Type'=>'text/xml' 会产生相同的错误。我已经验证了 xml,并且我知道访问令牌很好,因为我可以很好地使用它们来发出 GET 请求。
任何帮助将不胜感激,谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了解决方案,将其替换
为
Found the solution, it was replacing
with