开发者

How do I use LinkedIn API with Zend_OAuth?

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 network开发者_开发知识库s 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?


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/


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜