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

我有一个通过linkedin API验证用户的应用程序:

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

>是否可以向应用程序用户的子集发送消息? (即:黄金会员等你可以假设我已经存储了所有的地址)

我一直在寻找一段时间,找不到任何东西/

最佳答案 像这样的东西

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值