0

페이스 북 로그인 통합을 위해 Yii2 EAuth를 통합하려고합니다. Nodge/yii2-eauth에서 페이스 북의 이메일 ID를 얻는 방법

나는 ...... 사전에 ... 페이스 북의 이메일 ID를 얻을 수

public static function findIdentity($id) { 
     if (Yii::$app->getSession()->has('user-'.$id)) { 
      return new self(Yii::$app->getSession()->get('user-'.$id)); 
     } 
     else { 
      return isset(self::$users[$id]) ? new self(self::$users[$id]) : null; 
     } 
    } 

    /** 
    * @param \nodge\eauth\ServiceBase $service 
    * @return User 
    * @throws ErrorException 
    */ 
    public function findByEAuth($service) { 

     if (!$service->getIsAuthenticated()) { 
      throw new ErrorException('EAuth user should be authenticated before creating identity.'); 
     } 

     $id = $service->getServiceName().'-'.$service->getId(); 

     // echo $id;exit; 

     print_r($service->getAttribute('email')); 

     echo '<pre>'; 

     print_r($service->getAttributes()); 
     exit; 



     $attributes = array(
      'id' => $id, 
      'username' => $service->getAttribute('name'), 
      'authKey' => md5(@$id), 
      'profile' => $service->getAttributes(), 
     ); 


     $attributes['profile']['service'] = $service->getServiceName(); 
     Yii::$app->getSession()->set('user-'.$id, $attributes); 
     return new self($attributes); 
    } 

내가 이메일을 원한다, pls는 하나가 나를 도울 수있는 코드 아래

을 감사를 사용하고 * 모델 configaration했다

답변

1

나는 vendor \ nodge \ yii2-eauth \ src \ services \ FacebookOAuth2Service.php의 몇 가지 설정을 변경 한 후에 페이스 북에서 사용자의 이메일을 얻을 수 있었다. 편집 FacebookOAuth2Service.php

재정 protected $scopes = array(self::SCOPE_EMAIL);

그리고 fetchAttributes을 수정() 함수

. 이 형식은 다음과 같아야합니다.

protected function fetchAttributes() 
    { 
      $info = $this->makeSignedRequest('me'); 

      $this->attributes['id'] = $info['id']; 
      $this->attributes['name'] = $info['name']; 
      $this->attributes['url'] = $info['link']; 
      $this->attributes['email'] = $info['email']; 

      return true; 
    } 

시도해보십시오.