2013-04-30 1 views
0

내 웹 사이트 사용자에게 Janrain을 사용하고있어 소셜 미디어 계정으로 웹 사이트에 로그인 할 수 있습니다. 권한 부여, 로그인 및 사용자 프로필 데이터 가져 오기와 관련하여 모든 것이 잘 작동하지만 로컬 데이터베이스에 프로필 데이터를 저장하는 것이 잘못된 경우입니다. 예 : 사용자 이메일, 이름, 생년월일, 사진 등다른 변수에서 잰 레인을 통해 배열로 들어오는 데이터를 어떻게 저장해야합니까?

사용자가 앱을 승인하면 프로필 데이터가 아래 형식으로 표시되고이 데이터를 가져온 후 다른 변수에 저장하여 쉽게 삽입 할 수 있습니다. 데이터베이스

$ 이메일 = [이메일]; // 값은해야 [email protected]

$ 이름 = [표시 이름]; // 값이 PRANAV 바트의

$ 사진이어야한다 = [포토]; // 값이어야 https://graph.facebook.com/1190480706/picture?type=large

$ DOB = [생일]; // 값이어야 1989년 12월 20일

코드

<?php 
/** 
* Copyright 2011 
* Janrain Inc. 
* All rights reserved. 
*/ 
/** 
* Below is a very simple PHP 5 script that 
* implements an Engage token URL to collect 
* and output the results from auth_info. 
* The code below assumes you have the 
* CURL HTTP fetching library with SSL and 
* PHP JSON support. 
*/ 

ob_start(); 
require_once('../library/engage.auth.lib.php'); 
$debug_array = array('Debug out:'); 

/** 
* For a production script it would be better 
* to include (require_once) the apiKey in 
* from a file outside the web root to 
* enhance security. 
* 
* Set your API key (secret) in this file. 
* The varable is $api_key 
*/ 
require_once('engage-conf.php'); 

$token = $_POST['token']; 
$format = ENGAGE_FORMAT_JSON; 
$extended = $auth_info_extended; 

$result = engage_auth_info($api_key, $token, $format, $extended); 
if ($result === false) { 
    $errors = engage_get_errors(); 
    foreach ($errors as $error=>$label) { 
     $debug_array[] = 'Error: '.$error; 
    } 
} else { 
/** 
* On a successful authentication store 
* the auth_info data in the variable 
* $auth_info_array 
*/ 
    $array_out = true; 
    $auth_info_array = engage_parse_result($result, $format, $array_out); 
     //Put a printed copy in the debug. 
    $debug_array[] = print_r($auth_info_array, true); 
/** 
* This is the point to add code to do something with the Engage data. 
*/ 
} 

$errors = engage_get_errors(ENGAGE_ELABEL_ERROR); 
foreach ($errors as $error=>$label) { 
    $error_array[] = 'Error: '.$error; 
} 

/* 
* Uncomment lines below to get SDK level 
* debug data. Caution: This could result in 
* revealing the api_key. 
*/ 
//$debugs = engage_get_errors(ENGAGE_ELABEL_DEBUG); 
//foreach ($debugs as $debug=>$label) { 
// $debug_array[] = 'Debug: '.$debug; 
//} 

$the_buffer = ob_get_contents(); 
if (!empty($the_buffer)) { 
    $debug_array[] = 'Buffer: '.$the_buffer; 
} 
/* The variable (string) $the_debug will contain debug data. */ 
$the_debug = implode("\n", $debug_array); 
$the_error = implode("\n", $error_array); 
ob_end_clean(); 
?> 
<html> 
    <head> 
     <title>Janrain Engage token URL example</title> 
    </head> 
    <body> 

     <pre> 
      <?php echo $the_error; ?> 

      <?php echo $the_debug; ?> 
     </pre> 
    </body> 
</html> 

출력

Array 
(
    [stat] => ok 
    [profile] => Array 
     (
      [providerName] => Facebook 
      [identifier] => http://www.facebook.com/profile.php?id=1190480706 
      [verifiedEmail] => [email protected] 
      [preferredUsername] => PranavBhat's 
      [displayName] => Pranav Bhat's 
      [name] => Array 
       (
        [formatted] => Pranav Bhat's 
        [givenName] => Pranav 
        [familyName] => Bhat's 
       ) 

      [email] => [email protected] 
      [url] => http://www.facebook.com/bhats1989 
      [photo] => https://graph.facebook.com/1190480706/picture?type=large 
      [utcOffset] => 01:00 
      [address] => Array 
       (
        [formatted] => London, United Kingdom 
        [type] => currentLocation 
       ) 

      [birthday] => 1989-12-20 
      [gender] => male 
      [providerSpecifier] => facebook 
     ) 

    [limited_data] => false 
) 
+1

_ 실제 문제는 무엇입니까? 우리는 무료로 코드를 작성하지 않습니다. 적어도 문제를 먼저 풀려고 노력해야합니다. –

+0

@ChristianVarga Mate 나는 기본적으로 다른 코드를 시도했다. 배열에서 값을 꺼내 다른 변수에 할당하려고한다. 나에게 코드를 작성해 줄 것을 요청하는 것이 아니며, 코드를 작성하면 도움이 될 것입니다. – colourtheweb

+0

걱정하지 않아도 코드로 질문을 편집 한 것을 볼 수 있습니다. 그게 우리가 찾고있는 것입니다. :) 우리가 도울 수 있기 전에 당신이 시도한 것을 볼 필요가 있습니다. 그렇지 않으면 누군가를 위해 코드를 작성하라는 요청을 실제로 보입니다. –

답변

1

이 같은

(즉, 출력 $array라는 변수에 가정)의 값에 액세스 할 수 있도록, 그냥 연관 배열이다
$email = $array['profile']['email']; 
$name = $array['profile']['displayName']; 

+0

시원한 환호, 또한 내 질문을 업데이 트하고 코드를 내려 놔! – colourtheweb

+0

@colourtheweb 걱정하지 마시오, 데이터베이스 정렬 코드가 있습니까? 아니면 다음 단계입니까? –

+0

데이터베이스 코드는 AJAX를 사용하여 수행 할 삽입 쿼리가 될 것이고 세션에 로그인 한 사용자를 지정하는 것보다 큰 차이가 없습니다 !! 그냥 가치를 분리 해 주길 원했어 :). .. 도움 환호에 감사드립니다. – colourtheweb

관련 문제