I am writing an application that will receive information from VK. Stopped at the request for receiving the name and surname of the authorized user.

VKRequest request = VKApi.Account.getProfileInfo(); 

Studio Account underlines red and nothing happens.

Tell me how to write this query correctly. In what form will the answer come?

  • What do you write when you hover on Account? Alt + enter tried? - Silento
  • What does the studio write about Account? Usually in IDEA, in addition to underscore, some messages are shown. - Vartlok
  • When you hover the cursor writes "Cannot resolve symbol 'Account' alt + enter suggests: create class 'Account' create inner class 'Account' rename reference - S.TertJ

3 answers 3

As I remember in sdk there is no function for accounts of the type such as yours, but you can do it

 String token = VKSdk.getAccessToken().accessToken; VKParameters parameters = VKParameters.from(VKApiConst.ACCESS_TOKEN, token); VKRequest request = new VKRequest("account.getProfileInfo", parameters); request.executeWithListener(new VKRequestListener(MainActivity.this) { @Override public void onComplete(VKResponse response) { super.onComplete(response); String status = ""; try { JSONObject jsonObject = response.json.getJSONObject("response"); String first_name = jsonObject.getString("first_name"); String last_name = jsonObject.getString("last_name"); String screen_name = jsonObject.getString("screen_name"); status = jsonObject.getString("status"); } catch (JSONException e) { e.printStackTrace(); } } }); public class VKRequestListener extends VKRequest.VKRequestListener { private final Context mContext; public VKRequestListener(Context context) { mContext = context; } @Override public void onError(VKError error) { super.onError(error); if(error.errorCode == 14) { VKCaptchaDialog vkCaptchaDialog = new VKCaptchaDialog(error); vkCaptchaDialog.show(mContext, new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { } }); } } 

}

     VKRequest profileInfo1 = VKApi.users().get(); 

    Here such request with empty parameters returns the name and surname of the authorized user.

      Open this method ( getProfileInfo() ) and see how it works, how and where it receives data.

      And it highlights it with red, apparently it does not find it, it may not be there, and if it does, it must be connected (Eclipse is the keyboard shortcut ctrl + shift + O ).