Help with secure methods
rromanchuk opened this issue · 8 comments
Not a bug, just wondering if you can help me understand vk's documentation. I'm trying to use some of the sms methods located at http://vk.com/developers.php?oid=-17680044&p=secure.sendSMSNotification
VkontakteApi::Client.new(vk_token).secure.getSMS(uid: 41526347)
VkontakteApi::Error: VKontakte returned an error 5: 'User authorization failed: you should pass client_secret param to use secure methods' after calling method 'secure.getSMS' with parameters {"uid"=>"41526347"}.
i have my app secret in config, but it's still throwing an error. Any suggestions?
VkontakteApi.configure do |config|
# Authorization parameters (not needed when using an external authorization):
config.app_id = 'blah'
config.app_secret = 'blahblah'
end
AFAIK you need to pass your app_secret
as an additional parameter when calling secure methods. Something like this should work:
VkontakteApi::Client.new(vk_token).secure.getSMS(uid: 41526347, client_secret: Vkontakte.app_secret)
I'm getting closer. My guess is something messed up with my scopes, although I verified that i am asking for the "notify" scope. Maybe i'm using an old token? Looks like there is a lot of chatter about this method on google, but hard for me to parse with my shitty russian.
[3] pry(main)> u.vk_client.secure.getSMS(uid: 41526347, client_secret: VkontakteApi.app_secret)
VkontakteApi::Error: VKontakte returned an error 5: 'User authorization failed: server method is unavailable with user token.' after calling method 'secure.getSMS' with parameters {"uid"=>"41526347", "client_secret"=>"blah"}.
ahhh, maybe this is what i need http://vk.com/developers.php?oid=-17680044&p=Application_Server_Authorization
Yes, you are trying to call secure methods with a token you got from a usual server authorization, but secure methods require an application server authorization.
Try this instead:
vk = VkontakteApi.authorize(type: :app_server)
vk.secure.getSMS(uid: 41526347, client_secret: VkontakteApi.app_secret)
Getting closer, but it looks like this method is causing problems for a lot of developers
http://vk.com/topic-12254722_22166247
VkontakteApi.authorize(type: :app_server).secure.sendSMSNotification(client_secret: VkontakteApi.app_secret, uid: 41526347, message: "test")
VkontakteApi::Error: VKontakte returned an error 1: 'Unknown error occured' after calling method 'secure.sendSMSNotification' with parameters {"client_secret"=>"blah", "uid"=>"41526347", "message"=>"test"}.
It is a different method (topic is about secure.sendNotification
and you need secure.sendSMSNotification
). I don't really see what's causing the problem here unfortunately.
doh, i'm going to fork your https://github.com/7even/vkontakte_on_rails example and try adding a secure.sendSMS as a sanity check. I have a feeling it's a configuration error
Did you manage to find something out?