Good day!
I generated a special Personal access tokens on github. I want to search some code into private repositories. When I use curl all works fine:
curl -H 'Authorization: token <MY_PERSONAL_TOKEN>' -H 'Accept: application/vnd.github.v3.text-match+json' https://api.github.com/search/code?q=FieldDescriptionResponseChecker+@MY_PRIVATE_REPO&sort=stars&order=desc;
However when I try to use groovy HTTPBuilder
class GithubSearchService {
private String authToken
public GithubSearchService(String authToken) {
this.authToken = authToken
}
public void search(String query) {
def http = new HTTPBuilder('https://api.github.com')
http.request( GET, TEXT) { req ->
uri.path = '/search/code'
uri.query = [ q: query]
headers.'Authorization' = "token $authToken"
headers.'Accept' = 'application/vnd.github.v3.text-match+json'
response.success = { resp, reader ->
println "Got response: ${resp.statusLine}"
println "Content-Type: ${resp.headers.'Content-Type'}"
println reader.text
}
}
}
}
I have 403-Exception
Exception in thread "main" groovyx.net.http.HttpResponseException: Forbidden
at groovyx.net.http.HTTPBuilder.defaultFailureHandler(HTTPBuilder.java:642)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
......
Could you help, please, make groovy work?