2016-10-27 11 views
0

私はすべてがうまく働いていた、長い時間のためにV2.2を使用していました。 しかし何らかの理由でv2.8にアップグレードする必要があり、電子メールの取得がもう機能していません。 コードはどのように表示されるべきですか? (もちろんのAPI呼び出しの前に行われます)Facebook Graph API v2.8経由で電子メールを取得するにはどうすればよいですか?

FB.init({ 
    appId  : 'myid', 
    cookie  : true, 
    xfbml  : true, 
    version : 'v2.8' 
}); 

とログイン:初期化はこの介して行われる

FB.api('/me', function(response) { 
    var fn = ('first_name' in response) ? response.first_name : "null"; 
    var ln = ('last_name' in response) ? response.last_name : "null"; 
    var fid = ('id' in response) ? response.id : "null"; 
    var mail = ('email' in response) ? response.email : "null"; 
    ... 
}); 

:電子メールアドレスを取得し

の作業V2.2コード次のようになります。

FB.login(function(response) { 
    if (response.authResponse) { 
    processLogin(response); 
    } else { 
    // user clicked cancel 
    } 
}, {scope: 'public_profile,email'}); 

ソリューションそれは、「宣言フィールド」と呼ばれ、グラフAPIのV2.4に付属している

FB.api('/me', {fields: 'first_name,last_name,email,id'}, function(response) { 
    var fn = ('first_name' in response) ? response.first_name : "null"; 
    var ln = ('last_name' in response) ? response.last_name : "null"; 
    var fid = ('id' in response) ? response.id : "null"; 
    var mail = ('email' in response) ? response.email : "null"; 
    ... 
}); 
+0

[OK]を、それが複製にリンクするフェアです。しかし、私の質問はv2.8に関するもので、もう一方はv2.4に関するものです... – basZero

答えて

2
FB.api('/me', {fields: 'name,email'}, (response) => { 
    console.log(response); 
}); 

:ここ
は、APIの呼び出しで「宣言型のフィールドを」使用して作業V2.8ソリューションですhttps://developers.facebook.com/docs/apps/changelog#v2_4

+0

Facebookからのアップグレードガイドをv2.2からv2.8にチェックしましたが、彼らは言及しませんでしたこの。ありがとう! – basZero

+0

'function(response){'と '(response)=> {'の違いは何ですか? – basZero

+1

https://github.com/lukehoban/es6features#arrows – luschn

関連する問題