2014-11-22 54 views
0

我使用改装打造的Android应用程序Github上,但我从https://api.github.com/authorizations改造-u用户名:密码字段和范围阵列

我知道如何用命令卷曲的要求去做有麻烦检索令牌:

curl -X POST -H "Accept: Application/json" -u "username:password" -d '{"scopes": ["user","repo","gist","notifications","repo","repo:status"],"note":"GithubViewer Android App","client_id":"xxx","client_secret":"yyyy"}' "https://api.github.com/authorizations" 

我遇到了麻烦,知道如何设置Scopes数组和-u认证字段。我一直在使用“:基本用户名:密码验证”在命令行中尝试,但不工作,要么:(

这里是什么,我试图做一个样本:

RequestInterceptor interceptor = new RequestInterceptor() { 
     @Override 
     public void intercept(RequestFacade request) { 
        request.addHeader("Authentication", "Basic " + username + ":" + password); 
      } 
     }; 

RestAdapter restAdapter = new RestAdapter.Builder() 
     .setEndpoint(GithubClient.API_URL) 
      .setRequestInterceptor(interceptor) 
      .build(); 

任何建议?

谢谢

+0

你可以发布你做了什么吗? – Atieh 2015-02-02 00:14:42

+0

这就是我所做的。首先,我修改了我的请求,以发送带请求的@Body。我创建了一个可以序列化为该请求所需的类的类。 https://gist.github.com/fnk0/f3ef3d5d15d72bff3fb2 – 2015-02-02 19:57:19

+0

我想通了昨天该怎么做。我错过了那里的@Body注释,不得不创建一个基本的认证。谢谢!你完成了你的应用程序?我可以查看它8D – Atieh 2015-02-02 20:12:37

回答

1

我没有使用过改造,但我察觉的东西,可能会导致您的问题,您提供的是用户名:。密码作为验证头纯文本,然而应编码使用Base64编码。

String str = "username:password"; 
String base64EncodedUsernamePassword; 

try { 
    base64EncodedUsernamePassword = Base64.encode(str.getBytes("UTF-8"), Base64.NO_WRAP); 
} catch (UnsupportedEncodingException e) { 
    // Weird, no UTF-8 encoding found? 
} 
+0

帮助,谢谢!我想到了最后我的问题......我试图发送UrlFormEncoded数据到github api,他们只接受post请求中的普通json对象。 – 2014-11-24 16:57:58