I'm trying to use LinkedIn api to send message to a connection of the user but I find extreme lack of examples and lacking docs make it very hard to diagnose.
我正在尝试使用LinkedIn api向用户的连接发送消息,但我发现极端缺乏示例和缺乏文档使得诊断非常困难。
I do not want to request w_messages permission when user signs up, so I use javascript API to get a new access token with this permission and pass to server for SendMessage call only.
我不想在用户注册时请求w_messages权限,因此我使用javascript API获取具有此权限的新访问令牌,并仅传递给服务器以进行SendMessage调用。
On Client:
在客户端:
IN.init({
onLoad: "onLoadApi",
api_key: viewBag.clientSettings.LinkedInClientId,
authorize: false,
scope: "r_basicprofile r_network w_messages"
});
function onLoadApi() {
if (!IN.User.isAuthorized()) {
IN.User.authorize(sendMessage);
}
function sendMessage() {
var w_message_accesstoken = IN.ENV.auth.oauth_token;
$http.post("/MyApi/SendMessage/vBejds6Vh8", w_message_accesstoken);
}
}
On Server:
在服务器上:
string jsonData = "{\"subject\":\"test subject\",\"body\":\"testbody\",\"recipients\":{\"values\":[{\"person\":{\"_path\":\"/people/vBejds6Vh8\"}}]}}"
var response= "https://api.linkedin.com/v1/people/vBejds6Vh8/mailbox"
.SetQueryParam("oauth2_access_token", accessTokenPassedFromClient)
.PostJsonAsync(jsonData);
Result:
结果:
{"Request to https://api.linkedin.com/v1/people/vBejds6Vh8/mailbox?oauth2_access_token=xxxxx failed with status code 401 (Unauthorized)."}
1 个解决方案
#1
2
You are going to want to make this call as a POST call. You can only send a message on behalf of a member whose access token you have with the "w_messages" member permission.
您将要将此呼叫作为POST呼叫。您只能代表具有“w_messages”成员权限的访问令牌的成员发送消息。
A sample request of the POST should be: POST https://api.linkedin.com/v1/people/~/mailbox?oauth2_access_token=***
POST的示例请求应为:POST https://api.linkedin.com/v1/people/~/mailbox?oauth2_access_token=***
<?xml version='1.0' encoding='UTF-8'?>
<mailbox-item>
<recipients>
<recipient>
<person path='/people/~' />
</recipient>
<recipient>
<person path="/people/{id}" />
</recipient>
</recipients>
<subject>Congratulations on your new position.</subject>
<body>You're certainly the best person for the job!</body>
</mailbox-item>
#1
2
You are going to want to make this call as a POST call. You can only send a message on behalf of a member whose access token you have with the "w_messages" member permission.
您将要将此呼叫作为POST呼叫。您只能代表具有“w_messages”成员权限的访问令牌的成员发送消息。
A sample request of the POST should be: POST https://api.linkedin.com/v1/people/~/mailbox?oauth2_access_token=***
POST的示例请求应为:POST https://api.linkedin.com/v1/people/~/mailbox?oauth2_access_token=***
<?xml version='1.0' encoding='UTF-8'?>
<mailbox-item>
<recipients>
<recipient>
<person path='/people/~' />
</recipient>
<recipient>
<person path="/people/{id}" />
</recipient>
</recipients>
<subject>Congratulations on your new position.</subject>
<body>You're certainly the best person for the job!</body>
</mailbox-item>