使用LinkedIn API如何在xml消息中发送HTML

时间:2012-08-16 05:33:11

标签: api codeigniter oauth linkedin

您好我使用linkedin api发送邀请。在消息中

<?xml version='1.0' encoding='UTF-8'?>
<mailbox-item>
  <recipients>
    <recipient>
      <person path='/people/~'/>
    </recipient>
    <recipient>
      <person path="/people/abcdefg" />
    </recipient>
  </recipients>
  <subject>Congratulations on your new position.</subject>
  <body>You're certainly the best person for the job!</body>
</mailbox-item>

<body>部分我想添加一些HTML。

喜欢

<b>你肯定是这份工作的最佳人选!</b>

但问题是它显示为文本,因为它在朋友收到的消息中,我想要bold消息内容的instad。我怎样才能做到这一点 。是否应该进行任何配置。

我正在使用codeigniter

function send_messeges($access_token, $xml_atring) {

    $profile_url = "http://api.linkedin.com/v1/people/~/mailbox";
    $xml = '<?xml version="1.0" encoding="UTF-8" ?>
        <mailbox-item>
          <recipients>                
            ' . $xml_atring . '
          </recipients>
          <subject>'.$this->send_subject.'</subject>
          <body>'.$this->send_message.'</body>
        </mailbox-item>';
    $request = OAuthRequest::from_consumer_and_token($this->consumer, $access_token, "POST", $profile_url);
    $request->sign_request($this->method, $this->consumer, $access_token);
    $auth_header = $request->to_header("https://api.linkedin.com");
    $response = $this->httpRequest($profile_url, $auth_header, "POST", $xml);        
    return $response;

}

请帮忙。提前谢谢

1 个答案:

答案 0 :(得分:3)

如果你想在xml中包装html,你必须使用这样的结构:

<xmltag><![CDATA[<b>html text</b>]]></xmltag> 

但要小心阅读api文档:

https://developer.linkedin.com/documents/messaging-between-connections-api

  

body mailbox-item yes消息正文。不能包含HTML。   发送邮件的成员必须可以编辑。

这表明你不能在这里使用html。

但是,您可以使用基本字符串格式(如换行符)至少包含一些段落:

这是通过字符串中的\n(转义换行符)完成的。

相关问题