public static void main(String[] args)
{
try
{
OAuthClientRequest request = OAuthClientRequest
.tokenLocation("http://api.vkontakte.ru/oauth/authorize")
.setClientId("45XXXXXX")
.setUsername("[email protected]")
.setPassword("XXXXXXX")
.setClientSecret("XXXXXXXXXXXX")
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setRedirectURI("http://oauth.vk.com/blank.html")
.setScope("all")
.buildBodyMessage();/** or buildHeaderMessage() or buildQueryMessage()*/
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
oAuthClient.accessToken(request);
OAuthJSONAccessTokenResponse tokenResponse = oAuthClient.accessToken(request, OAuthJSONAccessTokenResponse.class);
}
catch (Exception e)
{
e.printStackTrace();
}
}
大家好,我正在尝试在VKontakte应用程序中上传一些图片和视频。运行时,它将引发以下异常。
OAuthProblemException{error='unsupported_response_type', description='Invalid response! Response body is not application/json encoded', uri='null', state='null', scope='null', redirectUri='null', responseStatus=0, parameters={}}
at org.apache.oltu.oauth2.common.exception.OAuthProblemException.error(OAuthProblemException.java:63)
at org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse.setBody(OAuthJSONAccessTokenResponse.java:70)
at org.apache.oltu.oauth2.client.response.OAuthClientResponse.init(OAuthClientResponse.java:56)
at org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse.init(OAuthAccessTokenResponse.java:52)
at org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory.createCustomResponse(OAuthClientResponseFactory.java:60)
at org.apache.oltu.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:111)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:65)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:55)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:71)
at net.eha.VKTest.main(VKTest.java:39)
我花了太多时间来寻找解决方案,但是我找不到办法。请提供任何帮助。谢谢。
最佳答案
我知道这已经很老了,但我想我会为将来的用户添加这个可能的解决方案,以防万一我将来搜索它!我几周前解决了类似的问题。我相信的问题是
OAuthJSONAccessTokenResponse tokenResponse = oAuthClient.accessToken(request,OAuthJSONAccessTokenResponse.class);
更改为:
GitHubTokenResponse tokenResponse = oAuthClient.accessToken(request,GitHubTokenResponse.class);
Facebook api给了我与oltu同样的错误。