LinkedIn编码的url调用 [英] LinkedIn API call with url encoded

查看:169
本文介绍了LinkedIn编码的url调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我打电话给:

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

它应该可以正常工作,但如果编码的网址(应该是这样的):

  https://api.linkedin.com/v1/people/ 〜:%28id,名字,姓氏%29 

我得到这个错误信息:

 <?xml version =1.0encoding =UTF-8standalone =yes?> 
<错误>
< status> 404< / status>
< timestamp> 1423577265744< / timestamp>
< request-id> 6B2UQSA25W< / request-id>
<错误代码> 0< /错误代码>
< message> [invalid.property.name]。无法在{人员}< / message>类型的资源中找到名称为{:%28id,名字,姓氏%29}的财产。
< / error>

您如何处理?

目前我无法更改代码,因为我的语言(Golang btw)使用标准包进行非常恰当的编码。这是我的代码:

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

您是否有解决方案, std lib代码?



自2013年以来面临同样问题的部分内容 https://developer.linkedin.com/forum/edit-i-dont-way-uris-look


<在创建请求之后,将URL Opaque字段设置为路径:

 <$ c 解决方案

$ c> r,err:= http.NewRequest(GET,https://api.linkedin.com,nil)
if err!= nil {
//处理错误
$ b r.Header.Set(Authorization,Bearer)
r.URL.Opaque =/ v1 / people /〜:(id,first-name,last-name) + respBody.AccessToken)
resp,err = http.DefaultCl ient.Do(r)

URL类型文档介绍了如何执行此操作。


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

解决方案

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.

这篇关于LinkedIn编码的url调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆