Twitter API call is stuck/hanging in middle of process

java

#1

I made a call to Twitter Status Update REST API to post a tweet on my timeline. But I didn’t get any response message.

root flush - signing request: https://api.twitter.com/1.1/statuses/update.json

root flush - setting token to: Token[********-***********]

root flush - generating signature...

root flush - using base64 encoder: DatatypeConverter

root flush - base string is: POST&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fupdate.json&oauth_consumer_key%3DA6zV8RC70fdDFIDzfFIpmA%26oauth_nonce%3D2847951734%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1478500810%26oauth_token%3D15656849-zp74Iyx3N6vhWE1FSunVEJVhPbmcZqFNWf1rV4nht%26oauth_version%3D1.0%26status%3D%2522People%2520laughed%2520at%2520this%2520AI%2520accelerator%2520for%2520Asia%2520This%2520is%2520its%2520killer%2520first%2520lineup%2522%2520https%253A%252F%252Fgoo.gl%252FFzWkk3

root flush - signature is: HxzfOd38R3lBQ2fVoIJKiYiZgY8=

root flush - appended additional OAuth parameters: { oauth_nonce -> 2847951734 , oauth_signature -> HxzfOd38R3lBQ2fVoIJKiYiZgY8= , oauth_token -> 15656849-zp74Iyx3N6vhWE1FSunVEJVhPbmcZqFNWf1rV4nht , oauth_consumer_key -> A6zV8RC70fdDFIDzfFIpmA , oauth_timestamp -> 1478500810 , oauth_signature_method -> HMAC-SHA1 , oauth_version -> 1.0 }

root flush - using Http Header signature

After printing the above specified log, program is waiting for the process to terminate. What may be the reason for the process to hang in the middle.


#2

What language are you using? What HTTP response code are you receiving? Can you share example code that demonstrates this issue?


#3

I have written the code in java.

Sample code.

public static String postTweet()
{
	final String URL_POST_TWEET = "https://api.twitter.com/1.1/statuses/update.json";
		
	try{
		OAuthRequest request = new OAuthRequest(Verb.POST, URL_POST_TWEET);
	
			request.setCharset("UTF-8");
			request.addBodyParameter("status","Some tweet");		
			twitter.signRequest(USER_TOKEN, request);			
			Response response = request.send();
			} catch(Exception e) {
		e.printStackTrace();
	}
		return "success";
}		

I didn’t get any http response code. Process has been struck after printing the above specified log.


#4

Is this org.scribe.model.OAuthRequest?

In that case, you’re not handling the return from the response object, AFAICT. Example.


#5

Hi,

Yes, this is org.scribe.model.OAuthRequest.

I have handled the response object,

response.getBody();

I have not included this in my sample code, but I have used it in my original program.

The problem here is, I didn’t get any response, because the request has been stuck/hanged.

My question is, why the request to twitter was stuck and Is there any way to handle these kind of issues.


#6

It is not clear - I’d have to debug inside whatever is going on at the network level to see what is happening. You should get some kind of HTTP response from the Twitter API.

I guess you’d need some error handling around this or have a mechanism for timing out the API call.


#7

As said before, I have written a java program using scribe library to post status message on my Twitter Timeline.

Sample code:

String URL_POST_TWEET = "https://api.twitter.com/1.1/statuses/update.json";
		
	try{
		OAuthRequest request = new OAuthRequest(Verb.POST, URL_POST_TWEET);
	
			request.setCharset("UTF-8");
			request.addBodyParameter("status","Some tweet");		
			twitter.signRequest(USER_TOKEN, request);			
			Response response = request.send();
System.out.println("Response:" +response.getBody());
			}
     catch(Exception e) {
		e.printStackTrace();
	}

When I had executed the above code in eclipse, I got the following response in the console:

root flush - signing request: https://api.twitter.com/1.1/statuses/update.json

root flush - setting token to: Token[********-***********]

root flush - generating signature...

root flush - using base64 encoder: DatatypeConverter

root flush - base string is: POST&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fupdate.json&oauth_consumer_key%3DA6zV8RC70fdDFIDzfFIpmA%26oauth_nonce%3D2847951734%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1478500810%26oauth_token%3D15656849-zp74Iyx3N6vhWE1FSunVEJVhPbmcZqFNWf1rV4nht%26oauth_version%3D1.0%26status%3D%2522People%2520laughed%2520at%2520this%2520AI%2520accelerator%2520for%2520Asia%2520This%2520is%2520its%2520killer%2520first%2520lineup%2522%2520https%253A%252F%252Fgoo.gl%252FFzWkk3

root flush - signature is: HxzfOd38R3lBQ2fVoIJKiYiZgY8=

root flush - appended additional OAuth parameters: { oauth_nonce -> 2847951734 , oauth_signature -> HxzfOd38R3lBQ2fVoIJKiYiZgY8= , oauth_token -> 15656849-zp74Iyx3N6vhWE1FSunVEJVhPbmcZqFNWf1rV4nht , oauth_consumer_key -> A6zV8RC70fdDFIDzfFIpmA , oauth_timestamp -> 1478500810 , oauth_signature_method -> HMAC-SHA1 , oauth_version -> 1.0 }

root flush - using Http Header signature

After printing these lines, process didn’t moved further and got stuck, without terminating.

I guess it has stuck at this line.
twitter.signRequest(USER_TOKEN, request);

What may be the reason for this issue. Can we handle these kind of issues. If yes? then please reply me with a solution.

Thanks


#8

If I was trying to reproduce this, I would probably use the debugger in Eclipse to step inside the twitter object and see why it is not returning from the .signRequest() method before executing request.send().

I’ve never personally used this scribe library so I can’t easily help you. If you are able to share your complete code somewhere then perhaps someone more familiar with it and who has the time to help you out, can take a look.


#9

Hi,

Thanks for the support. Would you recommend any other library other than Scribe or Twitter4j?