duanqianhuan3994 2015-02-10 14:12
浏览 120
已采纳

使用URL编码的LinkedIn API调用

For example, if I make a call to:

https://api.linkedin.com/v1/people/~:(id,first-name,last-name)

It should work fine, but if the URL encoded (and it should be) like this:

https://api.linkedin.com/v1/people/~:%28id,first-name,last-name%29

I get this error message:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
    <status>404</status>
    <timestamp>1423577265744</timestamp>
    <request-id>6B2UQSA25W</request-id>
    <error-code>0</error-code>
    <message>[invalid.property.name]. Couldn&#39;t find property with name {:%28id,first-name,last-name%29} in resource of type {Person}</message>
</error>

How can you deal with that?
Currently I cannot change the code because my language (Golang btw) do very properly encode this with standar package. Here is my code:

r, _ := http.NewRequest("GET", "https://api.linkedin.com/v1/people/~:(id,first-name,last-name)", nil)
r.Header.Set("Authorization", "Bearer "+respBody.AccessToken)
resp, err = http.DefaultClient.Do(r)

Do you have solution for this issue except rewrite std lib code?

Some what face with the same issue since 2013 here https://developer.linkedin.com/forum/edit-i-dont-way-uris-look

  • 写回答

1条回答 默认 最新

  • dongtangyi8962 2015-02-10 17:58
    关注

    Set the URL Opaque field to the path after creating the request:

    r, err := http.NewRequest("GET", "https://api.linkedin.com", nil)
    if err != nil {
      // handle error
    }
    r.URL.Opaque = "/v1/people/~:(id,first-name,last-name)"
    r.Header.Set("Authorization", "Bearer "+respBody.AccessToken)
    resp, err = http.DefaultClient.Do(r)
    

    The URL type documentation describes how to do this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写uniapp时遇到的问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流