英文:
How to upload photo into main album at my community via vk_api
问题
If I use login and password to auth I get "vk_api.exceptions.ApiError: [203] Access to group denied"
If I use access token I get "vk_api.exceptions.ApiError: [27] Group authorization failed: method is unavailable with group auth."
First way:
def upload_pic(filename, album_id, group_id):
vk_session = vk_api.VkApi(login=LOGIN, password=PASSWORD)
try:
vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
print(error_msg)
return
upload = vk_api.VkUpload(vk_session)
upload.photo(filename, album_id, group_id=group_id)
Second way:
def upload_pic(filename, album_id, group_id):
vk_session = vk_api.VkApi(token=TOKEN)
upload = vk_api.VkUpload(vk_session)
upload.photo(filename, album_id, group_id=group_id)
I tried to add auth block from the first way to the second one, but it didn't change anything.
英文:
If I use login and password to auth I get "vk_api.exceptions.ApiError: [203] Access to group denied"
If I use access token I get "vk_api.exceptions.ApiError: [27] Group authorization failed: method is unavailable with group auth."
First way:
def upload_pic(filename, album_id, group_id):
vk_session = vk_api.VkApi(login=LOGIN, password=PASSWORD)
try:
vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
print(error_msg)
return
upload = vk_api.VkUpload(vk_session)
upload.photo(filename, album_id, group_id=group_id)
Second way:
def upload_pic(filename, album_id, group_id):
vk_session = vk_api.VkApi(token=TOKEN)
upload = vk_api.VkUpload(vk_session)
upload.photo(filename, album_id, group_id=group_id)
I tried to add auth block from first way to second one but it nothing changed
rights for token
答案1
得分: 0
我不确定这是否是原因,但我记得vk_api使用关键字参数。
总的来说,这是可工作的代码:
def upload_pic(filename, album_id, group_id):
vk_session = vk_api.VkApi(login=LOGIN, password=PASSWORD)
try:
vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
print(error_msg)
return
upload = vk_api.VkUpload(vk_session)
upload.photo(filename, album_id=album_id, group_id=group_id)
英文:
I'm not sure that this is the reason but i remembered that vk_api uses keyword args
In general here's the working code
def upload_pic(filename, album_id, group_id):
vk_session = vk_api.VkApi(login=LOGIN, password=PASSWORD)
try:
vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
print(error_msg)
return
upload = vk_api.VkUpload(vk_session)
upload.photo(filename, album_id=album_id, group_id=group_id)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论