代码之家  ›  专栏  ›  技术社区  ›  Umesh

tumblr身份验证问题

  •  0
  • Umesh  · 技术社区  · 15 年前

    api文档建议我使用电子邮件和密码参数来验证凭据并获取帐户信息。 有人能告诉我我做错了什么吗。

        String url = "http://www.tumblr.com/api/authenticate";
        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, 20000);
        HttpConnectionParams.setSoTimeout(params, 20000);       
        DefaultHttpClient httpclient = new DefaultHttpClient(params);   
    
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(_username + ":" + _password); 
        httpclient.getCredentialsProvider().setCredentials(new AuthScope(null,-123),credentials);       
    
        HttpPost method = new HttpPost(url);        
        HttpResponse response = httpclient.execute(method);
        response.getStatusLine().toString(); // this gives me a 403 res code (Forbidden)..
    
    1 回复  |  直到 15 年前
        1
  •  3
  •   Fredrik Leijon    15 年前

    以下是我在应用程序中用于验证的内容:

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(
    "http://www.tumblr.com/api/authenticate");
    
        try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("email", Username));
        nameValuePairs.add(new BasicNameValuePair("password", Password));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        if (response.getStatusLine().getStatusCode() != 200) {
            return false;
        }
        return true;
    }