Hi,
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.commons.io.IOUtils;
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(
ConsumerKey,
ConsumerSecret);
consumer.setTokenWithSecret(AccessToken, AccessSecret);
HttpGet request = new HttpGet("https://ads-api.twitter.com/0/accounts/hkk5/funding_instruments?with_deleted=true&funding_instrument_ids=hw6ie");
consumer.sign(request);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request);
int statusCode = response.getStatusLine().getStatusCode();
System.out.println(statusCode + ":" + response.getStatusLine().getReasonPhrase());
System.out.println(IOUtils.toString(response.getEntity().getContent()));
}
}
I appreciate your help.