如何使用 linkedin api 发送消息/通知?

发布于 2024-11-17 13:27:53 字数 212 浏览 0 评论 0原文

我有一个通过 linkedin api 对用户进行身份验证的应用程序:

  • 应用程序是否可以向所有授权它的用户发送消息? (即:应用程序的系统通知)

  • 是否可以向应用程序用户的子集发送消息? (即:黄金会员等。您可以假设我将所有 linkedin ID 存储在某处)

我已经寻找了一段时间,但找不到任何内容/

i have an application that authenticates users through the linkedin api:

  • is it possible for an application to send messages to all users who authorized it? (ie: the app's system notifications)

  • is it possible to send a message to a subset of the application users? (ie: gold members etc. you can assume i have all the linkedin IDs stored somewhere)

i've been looking for a while, and can't find anything/

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

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

发布评论

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

评论(2

帅气尐潴 2024-11-24 13:27:53

像这样的

function message($subject, $body, $recipients)
{
    if (!is_array($recipients)) {
        throw new Exception('Recipients must be suplied as an array');
    }

    // Start document
    $xml = new DOMDocument('1.0', 'utf-8');

    // Create element for recipients and add each recipient as a node
    $elemRecipients = $xml->createElement('recipients');
    foreach ($recipients as $recipient) {
        // Create person node

        $person = $xml->createElement('person');
        $person->setAttribute('path', '/people/' . (string) $recipient);

        // Create recipient node
        $elemRecipient = $xml->createElement('recipient');
        $elemRecipient->appendChild($person);

        // Add recipient to recipients node
        $elemRecipients->appendChild($elemRecipient);

    }


    // Create mailbox node and add recipients, body and subject
    $elemMailbox = $xml->createElement('mailbox-item');
    $elemMailbox->appendChild($elemRecipients);
    $elemMailbox->appendChild($xml->createElement('body', ($body)));
    $elemMailbox->appendChild($xml->createElement('subject', ($subject)));

    // Append parent node to document
    $xml->appendChild($elemMailbox);

    $response = fetch('POST','/v1/people/~/mailbox', $xml->saveXML());

    return ($response);
}


function fetch($method, $resource, $body = '') {
    $params = array('oauth2_access_token' => $_SESSION['access_token'],
        'format' => 'json',
    );

    // Need to use HTTPS
    $url = 'https://api.linkedin.com' . $resource . '?' . http_build_query($params);
    // Tell streams to make a (GET, POST, PUT, or DELETE) request


    $context = stream_context_create(
        array('http' =>
            array('method' => $method,

                'header'=> "Content-Type:text/xml\r\n"
                    . "Content-Length: " . strlen($body) . "\r\n",
                'content' => ($body)
            )
        )
    );


    // Hocus Pocus
    $fp = fopen($url, 'r', false, $context);
    $response = file_get_contents($url, false, $context);
    $result =json_decode($response,true);

    return $result;}
message('Subject', 'body', array('id'));

函数从 代码示例 获取

Something like this

function message($subject, $body, $recipients)
{
    if (!is_array($recipients)) {
        throw new Exception('Recipients must be suplied as an array');
    }

    // Start document
    $xml = new DOMDocument('1.0', 'utf-8');

    // Create element for recipients and add each recipient as a node
    $elemRecipients = $xml->createElement('recipients');
    foreach ($recipients as $recipient) {
        // Create person node

        $person = $xml->createElement('person');
        $person->setAttribute('path', '/people/' . (string) $recipient);

        // Create recipient node
        $elemRecipient = $xml->createElement('recipient');
        $elemRecipient->appendChild($person);

        // Add recipient to recipients node
        $elemRecipients->appendChild($elemRecipient);

    }


    // Create mailbox node and add recipients, body and subject
    $elemMailbox = $xml->createElement('mailbox-item');
    $elemMailbox->appendChild($elemRecipients);
    $elemMailbox->appendChild($xml->createElement('body', ($body)));
    $elemMailbox->appendChild($xml->createElement('subject', ($subject)));

    // Append parent node to document
    $xml->appendChild($elemMailbox);

    $response = fetch('POST','/v1/people/~/mailbox', $xml->saveXML());

    return ($response);
}


function fetch($method, $resource, $body = '') {
    $params = array('oauth2_access_token' => $_SESSION['access_token'],
        'format' => 'json',
    );

    // Need to use HTTPS
    $url = 'https://api.linkedin.com' . $resource . '?' . http_build_query($params);
    // Tell streams to make a (GET, POST, PUT, or DELETE) request


    $context = stream_context_create(
        array('http' =>
            array('method' => $method,

                'header'=> "Content-Type:text/xml\r\n"
                    . "Content-Length: " . strlen($body) . "\r\n",
                'content' => ($body)
            )
        )
    );


    // Hocus Pocus
    $fp = fopen($url, 'r', false, $context);
    $response = file_get_contents($url, false, $context);
    $result =json_decode($response,true);

    return $result;}
message('Subject', 'body', array('id'));

function fetch from Code Sample

旧梦荧光笔 2024-11-24 13:27:53

该 API 支持的唯一消息传递是通过 消息传递 API,它只允许消息从一个连接发送到另一个连接...所以理论上,您(作为开发人员,而不是应用程序本身,因为它没有连接)可以向您的任何应用程序用户发送一条消息,表明您也碰巧已连接以某种方式。消息传递 API 非常清楚,尽管消息必须由特定操作触发,并且收件人的最大数量为 10。

所以简短的答案是不可能,尽管上面的方法可能是一种解决方法。另一种方法是在用户完成 LI 流程后直接询问他们的电子邮件地址,然后您可以根据需要联系他们,而不会遇到 API 限制/限制。

The only messaging supported by the API is via the Messaging API, which only allows for messages to be sent from one connection to another... so in theory, you (as in you the developer, not the application itself, as it has no connections) could send a message to any of your applications user's that you also happen to be connected to in some way. The Messaging API is pretty clear though that messages must be triggered by a specific action, and the maximum number of recipients is 10.

So the short answer is, not possible, although the above may be a bit of a workaround. An alternative would be to ask the user directly for their email address once they have completed the LI process and then you can contact them as you wish without running into API limits/restrictions.

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