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.

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

报告相同问题?