Reputation: 121
I am trying to use Scribe library to send API calls to Twitter v2 API with OAuth1 authentication. I manage to send GET users/me request successfully, but its fail on POST follow request.
public boolean followUser(String accountId, String userId) throws IOException, ExecutionException, InterruptedException {
OAuth1AccessToken twitterUserAccessToken = getTwitterUserAccessToken();
request = new OAuthRequest(Verb.POST, BASE_URL + "/users/" + accountId + "/following");
request.addHeader("Content-Type", "application/json");
request.addBodyParameter("target_user_id", userId);
service.signRequest(twitterUserAccessToken, request);
com.github.scribejava.core.model.Response response = service.execute(request);
System.out.println(response.getBody());
return response.isSuccessful();
}
This request fail with Status Code 401 Unauthorized
{
"title": "Unauthorized",
"type": "about:blank",
"status": 401,
"detail": "Unauthorized"
}
Everything is working, fine for GET users/me request which use the same authentication method OAuth1
public boolean userMe() throws IOException, ExecutionException, InterruptedException {
OAuth1AccessToken twitterUserAccessToken = getTwitterUserAccessToken();
request = new OAuthRequest(Verb.GET, BASE_URL + "/users/me");
service.signRequest(twitterUserAccessToken, request);
com.github.scribejava.core.model.Response response = service.execute(request);
return response.isSuccessful();
}
Can anybody familiar with Scribe give answer to this issue I also try to use RestAssured but the result is same even for GET users/me request.
Upvotes: 1
Views: 137