0
votes

i try to get the friends ids from Twitter i have the following cURL to get the friends list

curl --request 'POST' 'https://api.twitter.com/1.1/friends/ids.json' --data 'amp%3Bcount=5000&amp%3Bscreen_name=twitterapi&cursor=-1' --header 'Authorization: OAuth oauth_consumer_key="XXXXXXXXX", oauth_nonce="XXXXXXXXXXX", oauth_signature="XXXXXXXXXX", oauth_signature_method="HMAC-SHA1", oauth_timestamp="XXXXXX", oauth_token="XXXXXXXX", oauth_version="1.0"' --verbose

here i have the following doubt,how can i call the url

1

1 Answers

1
votes

'Curl' is just a library that is used to make HTTP requests in php. In android(java) you can achieve the same using the HttpURLConnection class. You can add your authentication string as a request property. Following example may help:

URL myURL = new URL(serviceURL);
HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
String oAuth = "Basic " + new String(new Base64().encode("oath authentication string"));
myURLConnection.setRequestProperty ("Authorization", oAuth);
myURLConnection.setRequestMethod("POST");
myURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
myURLConnection.setRequestProperty("Content-Length", "" + Integer.toString(postData.getBytes().length));
myURLConnection.setRequestProperty("Content-Language", "en-US");
myURLConnection.setUseCaches(false);
myURLConnection.setDoInput(true);
myURLConnection.setDoOutput(true);
//open the connection and write to the output stream & then read from input stream.

I hope this helps.