VKSdk постинг фото в альбом группы(Ошибка 15)
Всем привет,подскажите как на com.vk:androidsdk:1.6.5 постить фото в группу вк?
Обновить до более новой либы не могу,придется в проекте очень много сменить.
Нашел такой метод,но выдает ошибку: VKTestVKError (API errorVKError (code: 15; ; Access denied: no access to call this method)) при логине я сделал запрос доступа к фото и группам.
String token = VKAccessToken.currentToken().accessToken;
final Bitmap photo = getPhoto();
VKRequest request = VKApi.uploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.jpgImage(0.9f)), 0, TARGET_GROUP);
request.executeWithListener(new VKRequest.VKRequestListener() {
@Override
public void onComplete(VKResponse response) {
recycleBitmap(photo);
VKApiPhoto photoModel = ((VKPhotoArray) response.parsedModel).get(0);
makePost(new VKAttachments(photoModel));
}
@Override
public void onError(VKError error) {
System.out.println("VKTest" + error);
}
});
}
private Bitmap getPhoto() {
Bitmap b = null;
try {
b = BitmapFactory.decodeStream(this.getAssets().open("gasmask.png"));
} catch (IOException e) {
e.printStackTrace();
}
return b;
}
private static void recycleBitmap(@Nullable final Bitmap bitmap) {
if (bitmap != null) {
bitmap.recycle();
}
}
private void makePost(VKAttachments attachments) {
makePost(attachments, null);
}
private void makePost(VKAttachments attachments, String message) {
VKRequest post = VKApi.wall().post(VKParameters.from(VKApiConst.OWNER_ID, "-" + TARGET_GROUP, VKApiConst.ATTACHMENTS, attachments, VKApiConst.MESSAGE, message));
post.setModelClass(VKWallPostResult.class);
post.executeWithListener(new VKRequest.VKRequestListener() {
@Override
public void onComplete(VKResponse response) {
if (response!=null) {
VKWallPostResult result = (VKWallPostResult) response.parsedModel;
System.out.println("VKTest" +result);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("https://vk.com/wall-%d_%s", TARGET_GROUP, result.post_id)));
startActivity(i);
}
System.out.println("VKTest" + response.toString());
}
@Override
public void onError(VKError error) {
System.out.println("VKTest" + error.apiError != null ? error.apiError : error);
}
});
}