How to get email address from vk.api?

两盒软妹~` 提交于 2019-12-12 11:15:01

问题


Im trying to get email address. After success login i have firstname, lastname, all except email. please help.

VK.Auth.login(function (response) {
            if (response.session) {


            } else {

            }
        }, 4194304);

回答1:


There is no way to do that. Vk is specific social network. I have the same problem.




回答2:


When you get Access Token, VK also gives you Email and User ID, but you need specific permission for that - "email".




回答3:


vk.com now has that functionality. Try checking out this documentation page: https://vk.com/dev/permissions




回答4:


Yes this way does not give the email. But there is the way to get email via OAuth (for sites vk.com/dev/auth_sites), email will be returned in GET parameters along with token.

in Coffescript/Javascript you can use window.open(...)

appId = 'your app id'
redirectUri = 'your redirect uri'
url = 'https://oauth.vk.com/authorize?client_id='+appId+'&display=popup&redirect_uri='+redirectUri+'&response_type=token&scope=email'

newWin = window.open(url, 'vk-login', 'width=665,height=370')

And later you have two way to get email

  1. On redirect uri handler (server way)
  2. do redirect to any place of your site and every second check newWin.location.href a when it will be if (newHref.indexOf(redirectUri) != -1) then extract the parameter email (client way)



回答5:


you can use window.open

var url = 'https://oauth.vk.com/authorize?client_id=APP_ID&scope=email&redirect_uri=http://yoursite.com&response_type=token'

        var newWin = window.open(url, 'vk-login', 'width=665,height=370')
        newWin.onload = function() {
          var hash = newWin.location.hash
          console.log(hash)
        }


来源:https://stackoverflow.com/questions/25528771/how-to-get-email-address-from-vk-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!