LINEでのログインを実装しようと考えているのですがメールアドレスを取得しようと考えましたがうまくいきません。
トークンを取得しプロフィールの情報は取得ができました。
###common.php
php
1<?php 2define("LINE_CLIENT_ID", "○○"); 3define("LINE_CLIENT_SECRET", "○○"); 4define('LINE_CLIENT_CALLBACK', '○○'); 5?>
###index.html
php
1<? 2require_once 'common.php'; 3 4$url = sprintf( 5 "https://access.line.me/dialog/oauth/weblogin" 6 ."?response_type=code" 7 ."&client_id=%s" 8 ."&redirect_uri=%s" 9 ,LINE_CLIENT_ID 10 ,LINE_CLIENT_CALLBACK 11); 12 13header("Location: ".$url); 14exit; 15?>
###callback
php
1<?php 2require_once 'common.php'; 3 4if(!$_GET["code"]){ 5 echo 'エラー'; 6}else{ 7 // アクセストークン取得 8 $url = "https://api.line.me/v1/oauth/accessToken"; 9 10 $data = array( 11 "grant_type" => "authorization_code", 12 "client_id" => LINE_CLIENT_ID, 13 "client_secret" => LINE_CLIENT_SECRET, 14 "code" => $_GET["code"], 15 "redirect_uri" => "", 16 ); 17 18 $ch = curl_init(); 19 curl_setopt($ch, CURLOPT_URL, $url); 20 curl_setopt($ch, CURLOPT_POST, 1); 21 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 22 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 23 24 $response = curl_exec($ch); 25 curl_close($ch); 26 $result = (array)json_decode($response, true); 27} 28 29if (empty($result) || isset($result["error"])) { 30 echo "エラー"; 31}else{ 32 print_r($result); 33 /* 34 Array 35 ( 36 [mid] => xxxxxxxxxxxxxxxxxxxxxxxxx 37 [access_token] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 38 [token_type] => Bearer 39 [expires_in] => 2568710 40 [refresh_token] => xxxxxxxxxxxxxxxxxxxx 41 [scope] => 42 ) 43 */ 44 45 // プロフィール情報を取得 46 $url = "https://api.line.me/v2/profile"; 47 48 $ch = curl_init(); 49 curl_setopt($ch, CURLOPT_URL, "https://api.line.me/v2/profile"); 50 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $result["access_token"])); 51 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 52 $response = curl_exec($ch); 53 curl_close($ch); 54 55 $result = (array)json_decode($response, true); 56 var_dump($result); 57} 58if (empty($result) || empty($result["userId"])) { 59 echo "エラー"; 60}else{ 61 echo $result; 62 echo "ok"; 63 /* 64 Array 65 ( 66 [userId] => xxxxxxxxxxxxxxxx 67 [displayName] => ユーザー名 68 [pictureUrl] => ユーザー画像のURL 69 ) 70 */ 71} 72?>
あるサイトを参考にし作成いたしました。
メールアドレスを取得することは何か申請みたいなものが必要なのでしょうか?
それとも他に方法があるのでしょうか?
情報が少なく調べても解決いたしませんでした。
どなたか宜しくお願いいたします。

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。