Twitter API access error



I am new to Twitter API. I am using below code to connect to Ads API. Getting authentication error.

401:Authorization Required
{“errors”:[{“code”:“UNAUTHORIZED_ACCESS”,“message”:“This request is not properly authenticated”}],“request”:{“params”:{}}}

import oauth.signpost.OAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public class Tw {

  static String AccessToken = "asdfasdfa";
  static String AccessSecret = "erqwerqwerqwerqwer";
  static String ConsumerKey = "erqwerqwerqwer";
  static String ConsumerSecret = "erqwerqwerq";

 * @param args
public static void main(String[] args) throws Exception {
	OAuthConsumer consumer = new CommonsHttpOAuthConsumer(

    consumer.setTokenWithSecret(AccessToken, AccessSecret);
     HttpGet request = new HttpGet("");

      HttpClient client = new DefaultHttpClient();
    HttpResponse response = client.execute(request);

    int statusCode = response.getStatusLine().getStatusCode();
      System.out.println(statusCode + ":" + response.getStatusLine().getReasonPhrase());


I appreciate your help.


A 401 response implies that there is an issue with how you’re using OAuth in the request.

Are you sure that the app you are working with has access to the Ads API?



Thanks for your response. I had issues with Tokens when i created application last month. Twitter team said it was because the application was not white listed. The application is whitelisted on may7th. I got new tokens. I tried above code with these tokens. Not sure why i am still getting this error.

I noticed there is call back URL while creating application. What value do i need to provide in it. As we are not using web application i left it blank.