c#LinkedIn API dquail Oauth从当前状态变为新<;共享>;api

本文关键字:lt 共享 api gt Oauth dquail API 状态 c#LinkedIn | 更新日期: 2023-09-27 18:20:17

我从下载了dquail-LinkedinOauth-f169b1f

https://github.com/dquail/LinkedinOauth

我成功了。问题是-此代码使用旧的当前状态api,该api已被弃用,并且限制为140个字符的

https://developer.linkedin.com/documents/status-update-api

并已被共享api所取代,该api允许700个字符加上许多其他功能

https://developer.linkedin.com/documents/share-api

我编辑了代码以提供新的xml和新的URL,但我得到了一个错误。新代码是:

    private void btnUpdateStatus_Click(object sender, EventArgs e)
    {
        try
        {
            //string xml = "<?xml version='"1.0'" encoding='"UTF-8'"?>";
            //xml += "<current-status>" + txtNewStatus.Text + "</current-status>";
            string xml = "<?xml version='"1.0'" encoding='"UTF-8'"?><share>";
            xml += "<comment>" + txtNewStatus.Text + "</comment><visibility><code>anyone</code></visibility></share>";
            //string response = _oauth.APIWebRequest("PUT", "http://api.linkedin.com/v1/people/~/current-status", xml);
            string response = _oauth.APIWebRequest("PUT", "http://api.linkedin.com/v1/people/~/shares", xml);
            if (response == "")
                txtResults.Text += "'n'rYour new status updated.  view linkedin for status.";
        }
        catch (Exception exp)
        {
            txtResults.Text += "'n'rException: " + exp.Message;
        }
    }

我发送的XML是:

 <?xml version="1.0" encoding="UTF-8" ?> 
  <share>
  <comment>"Theres a lot of blood, sweat, and guts between dreams and success.", Paul Bryant</comment> 
  <visibility>
  <code>anyone</code> 
  </visibility>
  </share>

我得到的错误是:

"远程服务器返回错误:(405)方法不允许。"

c#LinkedIn API dquail Oauth从当前状态变为新<;共享>;api

您使用的是PUT,但是Share API需要POST作为方法。

405表示"您正在使用此端点不支持的HTTP方法"

至于原因,您没有更新当前状态,而是添加了一个新的共享。https://developer.linkedin.com/documents/share-api