如何将 LinkedIn API 与 Zend_OAuth 结合使用?

发布于 2024-10-20 14:14:09 字数 2057 浏览 1 评论 0原文

我正在为 LinkedIn API 编写一个类包装器,并且正在使用 Zend Framework 1.11.2。这是我的一个片段:

    $config = Pb_Portal::getInstance()->getConfig('linkedin.ini');

    $body = '<?xml version="1.0" encoding="UTF-8"?>';
    $body .= '<share>';
    $body .= '<comment>83% of employers will use social media to hire: 78% LinkedIn, 55% Facebook, 45% Twitter [SF Biz Times] http://bit.ly/cCpeOD</comment>';
    $body .= '<content>';
    $body .= '<title>Survey: Social networks top hiring tool - San Francisco Business Times</title>';
    $body .= '<submitted-url>http://sanfrancisco.bizjournals.com/sanfrancisco/stories/2010/06/28/daily34.html</submitted-url>';
    $body .= '<submitted-image-url>http://images.bizjournals.com/travel/cityscapes/thumbs/sm_sanfrancisco.jpg</submitted-image-url>';
    $body .= '</content>';
    $body .= '<visibility>';
    $body .= '<code>anyone</code>';
    $body .= '</visibility>';
    $body .= '</share>';

    $client = Zend_Oauth::getHttpClient();

    $client->setUri('http://api.linkedin.com/v1/people/~/shares');
    $client->setMethod(Zend_Http_Client::POST);
    $client->setRawData($body,'text/xml');
    $client->setHeaders('Content-Type', 'text/xml');
    $client->setParameterPost('oauth_consumer_key', $config->appKey);
    $client->setParameterPost('oauth_nonce', $config->appSecretKey);
    $client->setParameterPost('oauth_token', $acc->getToken());
    $client->setParameterPost('oauth_timestamp', time());
    $client->setParameterPost('oauth_signature_method', 'HMAC-SHA1');
    $client->setParameterPost('oauth_version', '1.0');

    $response = $client->request();

    $xml = @simplexml_load_string($response->getBody());

我有这样的回应:

SimpleXMLElement Object
(
    [status] => 401
    [timestamp] => 1299581073233
    [error-code] => 0
    [message] => Unknown authentication scheme
)

有人可以帮助我吗?我哪里出错了?

I'm writing a class wrapper for LinkedIn API and I'm using Zend Framework 1.11.2. Here is a snippet I have:

    $config = Pb_Portal::getInstance()->getConfig('linkedin.ini');

    $body = '<?xml version="1.0" encoding="UTF-8"?>';
    $body .= '<share>';
    $body .= '<comment>83% of employers will use social media to hire: 78% LinkedIn, 55% Facebook, 45% Twitter [SF Biz Times] http://bit.ly/cCpeOD</comment>';
    $body .= '<content>';
    $body .= '<title>Survey: Social networks top hiring tool - San Francisco Business Times</title>';
    $body .= '<submitted-url>http://sanfrancisco.bizjournals.com/sanfrancisco/stories/2010/06/28/daily34.html</submitted-url>';
    $body .= '<submitted-image-url>http://images.bizjournals.com/travel/cityscapes/thumbs/sm_sanfrancisco.jpg</submitted-image-url>';
    $body .= '</content>';
    $body .= '<visibility>';
    $body .= '<code>anyone</code>';
    $body .= '</visibility>';
    $body .= '</share>';

    $client = Zend_Oauth::getHttpClient();

    $client->setUri('http://api.linkedin.com/v1/people/~/shares');
    $client->setMethod(Zend_Http_Client::POST);
    $client->setRawData($body,'text/xml');
    $client->setHeaders('Content-Type', 'text/xml');
    $client->setParameterPost('oauth_consumer_key', $config->appKey);
    $client->setParameterPost('oauth_nonce', $config->appSecretKey);
    $client->setParameterPost('oauth_token', $acc->getToken());
    $client->setParameterPost('oauth_timestamp', time());
    $client->setParameterPost('oauth_signature_method', 'HMAC-SHA1');
    $client->setParameterPost('oauth_version', '1.0');

    $response = $client->request();

    $xml = @simplexml_load_string($response->getBody());

And I have this response:

SimpleXMLElement Object
(
    [status] => 401
    [timestamp] => 1299581073233
    [error-code] => 0
    [message] => Unknown authentication scheme
)

Can somebody help me? Where I go wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以为你会在 2024-10-27 14:14:09

我遇到了类似的问题(尽管我只是检索用户信息)。这个链接有很大帮助。您可以允许令牌根据您的选项构造 http 客户端,而不是将参数构造为 get 变量。

http://www.contentwithstyle.co.uk/content/linkedin-and- zendoauth/

I had a similar problem (although I am just retrieving user info). This link helped a great deal. Instead of constructing the params as get variables, you allow the token to construct the http client from your options.

http://www.contentwithstyle.co.uk/content/linkedin-and-zendoauth/

带上头具痛哭 2024-10-27 14:14:09

您可能需要更改编写类包装器的方式。

您可以从这篇文章中获取想法并接受那里的答案!

Linkedin:如何使用访问令牌进行 api 调用?

祝你好运

You may need to change the way you are writing class wrapper.

You can take idea from this post and accepted answer there!!

Linkedin: How to make api calls using access token?

best of luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文