我尝试使用OAuth1.0身份验证.我试试邮递员. Postman guide表示您可以设置以下值:
消费者密钥:RKCGzna7bv9YD57c
消费者秘密:D EdQ-gs $ – %@ 2Nu7
在postman上我设置了这些值,并选中“将params添加到标题”.响应状态代码为200.
当我点击将params添加到标题时,postman生成以下值:
OAuth oauth_consumer_key=”RKCGzna7bv9YD57c”,oauth_signature_method=”HMAC-SHA1″,oauth_timestamp=”1499874836″,oauth_nonce=”T5zV4W”,oauth_version=”1.0″,oauth_signature=”YDXruS98dvqQs7Ra3a3ZWczkEpM%3D”
public Map<String, String> getheaders() throws AuthFailureError { final Map<String, String> headers = new HashMap<>(); headers.put("Authorization", headerValue); // headerValue is taken from postman return headers;}
有用.但根据postman guide,我预计分配消费者密钥和消费者秘密就足够了.
以下用法不起作用.它表示{“status”:“fail”,“message”:“Timestamp缺失或不是数字”}.
Shoud我使用headers.put(“授权”,authString);?
我还必须给出时间戳,签名和签名方法吗?
headers.put("oauth_consumer_key","RKCGzna7bv9YD57c");headers.put("oauth_signature_method","HMAC-SHA1");headers.put("oauth_timestamp","1499874836");headers.put("oauth_nonce", "0Jx39O");headers.put("oauth_signature_method","HMAC-SHA1");headers.put("oauth_signature", "GGKc%2FuFoAWIflEsfE1%2B6mZau3vM%3D");headers.put("oauth_timestamp","1499872116");headers.put("oauth_version","1.0");
解决方法:
new Thread() { @OverrIDe public voID run() { String RESOURCE_URL = "url"; String ScopE = "*"; //all permissions Response response; OAuthRequest request; String responsebody = ""; OAuthService service = new ServiceBuilder().provIDer(OneLeggedAPI10.class) .APIKey("key") .APISecret("secrect") .signatureType(SignatureType.queryString) .deBUG() /*.scope(ScopE).*/ .build(); request = new OAuthRequest(Verb.GET, RESOURCE_URL); service.signRequest(new Token("", ""), request); // Now let's go and ask for a protected resource! Log.d("scribe", "Now we're going to access a protected resource..."); try { response = request.send(); if (response.isSuccessful()) { responsebody = response.getbody(); Log.e("response", responsebody); } } catch (Exception e) { e.printstacktrace(); } } }.start();
总结 以上是内存溢出为你收集整理的android – Volley OAuth1.0认证全部内容,希望文章能够帮你解决android – Volley OAuth1.0认证所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)