URL Encoding in http.NewRequest and LinkedIn API Field Selectors

451 views
Skip to first unread message

Paul van Brouwershaven

unread,
Apr 3, 2013, 5:12:31 AM4/3/13
to golan...@googlegroups.com
Hi,

I'm running into the following issue when using the LinkedIn API from Go:

LinkedIn is using "(" and ")" to request specific fields from the API, see:
https://developer.linkedin.com/documents/understanding-field-selectors

When I use the url listed in the example:
http.NewRequest("GET", "https://api.linkedin.com/v1/companies/1337:(id,website-url,locations)", nil)

I get the following error message:
{
  "errorCode": 0,
  "message": "[invalid.property.name]. Couldn't find property with name {:%28id,website-url,locations%29} in resource of type {Company}",
  "requestId": "1COW9HZ53U",
  "status": 404,
  "timestamp": 1364979752628
}

Go is automatically escaping the URL where LinkedIn does not want to this part of the URL escaped:
"When URL-encoding your resource URLs, ensure that the parenthesis used in selectors remain unescaped."

Now I could write a raw http client but I was hoping that there is an easier way to solve this issue?

Thanks,

Paul

Volker Dobler

unread,
Apr 3, 2013, 7:17:22 AM4/3/13
to golan...@googlegroups.com
You could try to set the Opaque field of Request.URL to
"/v1/companies/1337:(id,url,loc)" after constructing the
request but before Do- or Get-ing with this request.

(Completely untried suggestion).

V.

Brad Fitzpatrick

unread,
Apr 3, 2013, 11:28:29 AM4/3/13
to Volker Dobler, golang-nuts
Yes.  You'll want to set Opaque on your fields.  You can write a new function to wrap NewRequest and modify the Opaque field afterwards.  See the docs below http://tip.golang.org/pkg/net/url/#URL


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Paul van Brouwershaven

unread,
Apr 4, 2013, 8:30:23 AM4/4/13
to golan...@googlegroups.com, Volker Dobler
Thanks, setting the opaque value for the url solved my problem!

httpReq, err := http.NewRequest("GET", "https://api.linkedin.com"+ requestUrl +"?"+ qs.Encode(), nil)
httpReq.URL.Opaque = requestUrl
httpReq.Header.Add("x-li-format", "json")
resp, err := client.Do(httpReq)
Reply all
Reply to author
Forward
0 new messages