LinkedIn API oauth与发送消息node.js有关

时间:2013-08-07 22:10:40

标签: node.js api linkedin

我有同样的问题:

How to post to LinkedIn "Share" with node-auth?

基本上我使用的是linkedin-js NPM模块,它可以很好地处理GET请求。我正在使用模块与护照相关联,并成功生成了oauth令牌和秘密。当POST不能用于消息传递时,我进入oauth依赖库并将所有Content-Type头文件更改为application / json,将X-li格式头文件更改为json。此外,我所有其他基地都被涵盖。我在范围内设置了“w_messages”,其他请求正在运行。

我真的不需要x-li格式的标头,因为我有application / json标头。我唯一能想到的是访问令牌是关闭的(可能是我缺少的一步 - 这是不可能的,因为所有其他请求身份验证工作的请求)或明文签名被application / json Content-Type抛出(跟随错误)不被抛出):

  if( signatureMethod != "PLAINTEXT" && signatureMethod != "HMAC-SHA1")
throw new Error("Un-supported signature method: " + signatureMethod )

我从这个错误消息开始:

{ statusCode: 401,
data: '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<error>\n  <status>401</status>\n  <timestamp>1375876823051</timestamp>\n  
<request-id>0WFU40UZP8</request-id>\n  <error-code>0</error-code>\n  <message>[unauthorized]. OAU:fgb949d9gb66|427a55ea-a05e-4494-88f5-a33230bd719a|*01|*01:1375876915:WWqVTAe9WQneEf8ezL6Yl7DMyV4=</message>\n</error>\n' }

收到以下错误消息:

{ statusCode: 401,
data: '{\n  "errorCode": 0,\n  "message": "[unauthorized]. 
OAU:fgb949d9gb66|ce1f124c-1e10-4abc-8777-55bbd9621100|*01|*01:1375913097:EH90Q69mhGRwiCVcknimzAUnLqI=",\n  
"requestId": "KOYHE8K0M6",\n  "status": 401,\n  "timestamp": 1375913004009\n}' }

这是api调用和相应的oauth调用:

linkedinClient.apiCall('POST', '/people/~/mailbox',
    {
        "token": {
            "oauth_token_secret": tokenSecret
            , "oauth_token": token
        },
        "mailbox-item": {"recipients": {
            "values": [
                {
                    "person": {
                        "_path": people,
                    }
                }]
        },
        "subject": subject,
        "body": body}
    }
    , function (error, result) {
        if (result){
            req.io.emit('success', {success : "LinkedIn message sent successfully."});
        }
        console.log(error);
    }
);

var CLIENT = {
oauth: new OAuth(
  'https://api.linkedin.com/uas/oauth/requestToken'
, 'https://api.linkedin.com/uas/oauth/accessToken'
, key
, secret
, '1.0A'
, redirect
, 'HMAC-SHA1'
, null
, {'Accept': '*/*', 'Connection': 'close', 'X-li-format': 'json', 'Content-Type': 'application/json'}
)
}

CLIENT.oauth.post(
    _rest_base + path
  , token.oauth_token
  , token.oauth_token_secret
  , params
  , 'application/json'
  , requestCallback(callback)
  );

0 个答案:

没有答案