gpt4 book ai didi

javascript - LinkedIn 向联系人发送消息

转载 作者:行者123 更新时间:2023-11-29 21:54:34 26 4
gpt4 key购买 nike

我正在尝试使用 LinkedIn api 向用户连接发送消息,但我发现极度缺乏示例和文档使得诊断非常困难。

我不想在用户注册时请求 w_messages 权限,所以我使用 javascript API 获取具有此权限的新访问 token 并传递给服务器以仅供 SendMessage 调用。

在客户端:

 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);
}
}

在服务器上:

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);

结果:

{"Request to https://api.linkedin.com/v1/people/vBejds6Vh8/mailbox?oauth2_access_token=xxxxx failed with status code 401 (Unauthorized)."}

最佳答案

您将要将此调用作为 POST 调用进行。您只能代表您拥有“w_messages”成员权限的访问 token 的成员发送消息。

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>

关于javascript - LinkedIn 向联系人发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27115114/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com