2015-03-01 6 views
6

Sto lavorando su twitter digits api per integrarlo nel mio sito web che deve verificare l'unicità dell'utente.Come gestire l'API di Twitter Digits per il Web

Questo è un link, è l'unico articolo che illustra ufficialmente come implementare cifre per il web.

Nell'articolo, trovo il fatto che devo preoccuparmi per il server Web a differenza di Digits for IOS. Ma NESSUNA INFORMAZIONE su cosa dovrei fare sul mio server web!

Cosa devo scrivere in PHP per la programmazione lato server per ottenere l'ID utente e il numero di telefono ??

+0

collegamento non funziona pls help me per ottenere quel link o codice di esempio, voglio anche implementare le cifre auth con OAuth insi de webapi. – Neo

risposta

2

Nella demo, http://s.codepen.io/digits/debug/gbrgYV

dopo l'accesso, mostra un comando ricciolo.

Utilizzare i dati di risposta per riprodurli sul lato server e fornire una risposta con il numero di telefono e l'ID.

Anche se, non so perché, quando il numero di telefono è nuovo, ci vuole un po 'per restituire il numero di telefono.

+1

Link è morto puoi riscrivere? – Ritzor

2

Va bene, qui è la piena attuazione:

Js

//include js 
<script type="text/javascript" id="digits-sdk" src="https://cdn.digits.com/1/sdk.js" async></script> 
<script> 
/* Initialize Digits for Web using your application's consumer key that Fabric generated */ 
    document.getElementById('digits-sdk').onload = function() { 
     Digits.init({ consumerKey: '*********' }); 
    }; 

    /* Launch the Login to Digits flow. */ 
    function onLoginButtonClick(phone_number=''){ 
     if(phone_number!='') 
     { 
      //Digits.logIn({ 
      Digits.embed({ 
       phoneNumber : phone_number, 
       container : '.my-digits-container' //remove this if u will use Digits.logIn 
      }) 
      .done(onLogin) /*handle the response*/ 
      .fail(onLoginFailure); 
     } 
    } 

    /* Validate and log use in. */ 
    function onLogin(loginResponse){ 
     // Send headers to your server and validate user by calling Digits’ API 
     var oAuthHeaders = loginResponse.oauth_echo_headers; 
     var verifyData = { 
      authHeader: oAuthHeaders['X-Verify-Credentials-Authorization'], 
      apiUrl: oAuthHeaders['X-Auth-Service-Provider'], 
     }; 

     var request = $.ajax({ 
      url: "<?php echo $url;?>", 
      method: "POST", 
      dataType: "json", 
      data: { 
       verifyData:verifyData, 
      } 
     }); 
     request.done(function (data) {    
      console.log(data); 
     }); 
     request.fail(function (jqXHR, textStatus) { 
      alert('fail'); 
     }); 
    } 

    function onLoginFailure(loginResponse){   
     alert('Something went wrong, Please try again'); 
    } 
</script> 

codice PHP

Ora avete un URL e colpo di testa di cifre allora si può utilizzare sotto il codice:

$apiUrl = 'https://api.digits.com/1.1/sdk/account.json'; 
$authHeader = 'OAuth oauth_consumer_key="**********", oauth_nonce="****", oauth_signature="****", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1481554529", oauth_token="*****", oauth_version="1.0"'; 

// Create a stream 
$opts = array(
    'http'=>array(
    'method'=>"GET", 
    'header'=>"Authorization: {$authHeader}" 
) 
); 

$context = stream_context_create($opts); 

// Open the file using the HTTP headers set above 
$file = file_get_contents($apiUrl, false, $context); 

$final_output = array(); 
if($file) 
{ 
    $final_output = json_decode($file,true); 
} 
print_r($final_output); 
Problemi correlati