Created my standalone app. I get token from VK using ScribeJava

Everything is received, all is well. But, when I try to display a test publication on a wall, an error occurs:

com.vk.api.sdk.exceptions.ApiAccessException: Access denied (15): Access denied: no access to call this method at com.vk.api.sdk.exceptions.ExceptionMapper.parseException(ExceptionMapper.java:37) at com.vk.api.sdk.client.ApiRequest.execute(ApiRequest.java:73) at com.killersssurprise.SocialMedia.VkontakteExample.main(VkontakteExample.java:122) 

The code itself has the form:

  public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "ID приложения"; final String clientSecret = "Секретный код приложения"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) .scope("wall,offline") // разрешения на действия со стеной и постоянный доступ .callback("https://google.com.ua/") .build(VkontakteApi.instance()); final Scanner in = new Scanner(System.in); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); System.out.println(); // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); System.out.print(">>"); final String code = in.nextLine(); System.out.println(); // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getCode()); System.out.println(response.getBody()); System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); try { JSONObject jo = new JSONObject(response.getBody()); new Print(true, ""+jo.toString()); new Print(true, "my array is: "+jo.getJSONArray("response")); JSONArray responce = jo.getJSONArray("response"); new Print(true, "my id is: "+responce.getJSONObject(0).getInt("uid") ); new Print(true, "acess token: "+accessToken.getAccessToken()); } catch (JSONException e) { e.printStackTrace(); } TransportClient transportClient = new HttpTransportClient(); VkApiClient vk = new VkApiClient(transportClient); try { UserActor userActor = new UserActor(new JSONObject(response.getBody()).getJSONArray("response").getJSONObject(0).getInt("uid"), accessToken.getAccessToken()); try { vk.wall().post(userActor).message("Test message").execute(); } catch (ApiException e) { e.printStackTrace(); } catch (ClientException e) { e.printStackTrace(); } } catch (JSONException e) { e.printStackTrace(); } } 

What is done wrong? Why does this error occur? The scope passed the required request, the token is received, and there is no access to the method.

  • and through the poster can make a request with a token? - Bohdan Korinnyi
  • sorry, what a poster? - Killersssurprise
  • one of the REST client - Bohdan Korinnyi

1 answer 1

The problem was solved by changing the callback to https://oauth.vk.com/blank.html .

  final OAuth20Service service = new ServiceBuilder() .apiKey(clientId) .apiSecret(clientSecret) .state(secretState) .scope("wall,offline") // разрешения на действия со стеной и постоянный доступ // не работает //.callback("https://google.com.ua/") //работает .callback("https://oauth.vk.com/blank.html") .build(VkontakteApi.instance()); 

The problem is due to the fact that for standalone applications, it is forbidden to use some methods by default (including wall, even if we ask for rights in the scope) if the callback goes to a different address than " https://oauth.vk.com/blank. html . ".

Link with a detailed explanation of this and other problems