Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. com.vk.api.sdk.exceptions.ApiAccessException: Access denied (15): Access denied: no access to call this method
  2. at com.vk.api.sdk.exceptions.ExceptionMapper.parseException(ExceptionMapper.java:37)
  3. at com.vk.api.sdk.client.ApiRequest.execute(ApiRequest.java:73)
  4. at com.killersssurprise.SocialMedia.VkontakteExample.main(VkontakteExample.java:122)
  5.  
  6. public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
  7. // Replace these with your client id and secret
  8. final String clientId = "ID приложения";
  9. final String clientSecret = "Секретный код приложения";
  10. final String secretState = "secret" + new Random().nextInt(999_999);
  11. final OAuth20Service service = new ServiceBuilder()
  12. .apiKey(clientId)
  13. .apiSecret(clientSecret)
  14. .state(secretState)
  15. .scope("wall,offline") // разрешения на действия со стеной и постоянный доступ
  16. .callback("https://google.com.ua/")
  17. .build(VkontakteApi.instance());
  18. final Scanner in = new Scanner(System.in);
  19.  
  20. System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
  21. System.out.println();
  22.  
  23. // Obtain the Authorization URL
  24. System.out.println("Fetching the Authorization URL...");
  25. final String authorizationUrl = service.getAuthorizationUrl();
  26. System.out.println("Got the Authorization URL!");
  27. System.out.println("Now go and authorize ScribeJava here:");
  28. System.out.println(authorizationUrl);
  29. System.out.println("And paste the authorization code here");
  30. System.out.print(">>");
  31. final String code = in.nextLine();
  32. System.out.println();
  33.  
  34. // Trade the Request Token and Verfier for the Access Token
  35. System.out.println("Trading the Request Token for an Access Token...");
  36. final OAuth2AccessToken accessToken = service.getAccessToken(code);
  37. System.out.println("Got the Access Token!");
  38. System.out.println("(if your curious it looks like this: " + accessToken
  39. + ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
  40. System.out.println();
  41.  
  42. // Now let's go and ask for a protected resource!
  43. System.out.println("Now we're going to access a protected resource...");
  44. final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
  45. service.signRequest(accessToken, request);
  46. final Response response = service.execute(request);
  47. System.out.println("Got it! Lets see what we found...");
  48. System.out.println();
  49. System.out.println(response.getCode());
  50. System.out.println(response.getBody());
  51.  
  52. System.out.println();
  53. System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");
  54.  
  55.  
  56.  
  57. try {
  58. JSONObject jo = new JSONObject(response.getBody());
  59. new Print(true, ""+jo.toString());
  60. new Print(true, "my array is: "+jo.getJSONArray("response"));
  61. JSONArray responce = jo.getJSONArray("response");
  62. new Print(true, "my id is: "+responce.getJSONObject(0).getInt("uid") );
  63. new Print(true, "acess token: "+accessToken.getAccessToken());
  64.  
  65. } catch (JSONException e) {
  66. e.printStackTrace();
  67. }
  68.  
  69. TransportClient transportClient = new HttpTransportClient();
  70. VkApiClient vk = new VkApiClient(transportClient);
  71.  
  72. try {
  73. UserActor userActor = new UserActor(new JSONObject(response.getBody()).getJSONArray("response").getJSONObject(0).getInt("uid"),
  74. accessToken.getAccessToken());
  75.  
  76. try {
  77. vk.wall().post(userActor).message("Test message").execute();
  78. } catch (ApiException e) {
  79. e.printStackTrace();
  80. } catch (ClientException e) {
  81. e.printStackTrace();
  82. }
  83.  
  84. } catch (JSONException e) {
  85. e.printStackTrace();
  86. }
  87.  
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement