Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement