401 Unauthorized, but only with oAuth2 and only when using a cursor


#1

This one has me stumped. I have looked through all of the posts here about 401s and what circumstances can cause it. So far I haven’t found anything that matches my present problem.

I have an application which has been fully authorized and I’ve set up my keys. It monitors its rate limit status so that it doesn’t make a request when it has no requests. It starts in application authorization mode (oAuth2) and will switch to oAuth if it needs more requests. This has all worked fine up until two days ago when I started using Followers/IDs and using the cursor to get the next batch of results. I can get the first batch using -1 as the cursor fine. However, the second batch, when I use the cursor given back by the initial request, I get a 401 Unauthorized. I temporarily disabled oAuth2 to use regular oAuth and it works fine. No issues with a 401 when following the cursor. Below I’ve pasted the dump of the HTTP requests using oAuth2. The first one works, the second one, which I run immediately afterwards, fails.

HttpRequest{
	requestMethod=GET,
	url='https://api.twitter.com/1.1/followers/ids.json?user_id=999999999&cursor=-1&include_entities=true', 
	postParams=null, 
	authentication=OAuth2Authorization{
		consumerKey='******************************************', 
		consumerSecret='******************************************', 
		token=OAuth2Token{
		 	tokenType='bearer', 
		 	accessToken='******************************************'
		 }
	},
	requestHeaders={
		X-Twitter-Client-Version=4.0.3, 
		X-Twitter-Client-URL=http://twitter4j.org/en/twitter4j-4.0.3.xml, 
		X-Twitter-Client=Twitter4J, 
		User-Agent=twitter4j http://twitter4j.org/ /4.0.3,
		Accept-Encoding=gzip
	}
}

HttpRequest{
	requestMethod=GET, 
	url='https://api.twitter.com/1.1/followers/ids.json?cursor=1468041278337766052&include_entities=true', 
	postParams=null, 
	authentication=OAuth2Authorization{
		consumerKey='******************************************', 
		consumerSecret='******************************************', 
		token=OAuth2Token{
			tokenType='bearer', accessToken='******************************************'
		}
	}, 
	requestHeaders={
		X-Twitter-Client-Version=4.0.3, 
		X-Twitter-Client-URL=http://twitter4j.org/en/twitter4j-4.0.3.xml, 
		X-Twitter-Client=Twitter4J, 
		User-Agent=twitter4j http://twitter4j.org/ /4.0.3, 
		Accept-Encoding=gzip
	}
}