2015-03-01 9 views
6

Tôi đang làm việc trên số api twitter để tích hợp nó vào trang web của tôi cần xác minh tính độc đáo của người dùng.Cách xử lý API Twitter Digits cho Web

Dưới đây là link, đó là bài viết duy nhất minh họa chính thức cách triển khai chữ số cho web.

Trong bài viết, tôi thấy thực tế là tôi phải quan tâm đến máy chủ web không giống như chữ số cho IOS. Nhưng KHÔNG CÓ THÔNG TIN về Tôi nên làm gì trên máy chủ web của mình!

Tôi nên viết gì trong PHP để lập trình phía máy chủ để lấy ID người dùng và Số điện thoại ??

+0

liên kết không hoạt động xin giúp tôi nhận được liên kết hoặc mã mẫu, tôi cũng muốn triển khai chữ số auth với OAuth insi de webapi. – Neo

Trả lời

2

Trong bản demo, http://s.codepen.io/digits/debug/gbrgYV

sau khi bạn đăng nhập, nó sẽ hiển thị lệnh curl.

Sử dụng dữ liệu phản hồi để tạo lại dữ liệu ở phía máy chủ của bạn và nó sẽ trả lời bạn bằng số điện thoại và ID.

Mặc dù, tôi không biết tại sao, khi số điện thoại mới, phải mất một lúc để trả lại cho bạn số điện thoại.

+1

Liên kết đã chết bạn có thể viết lại không? – Ritzor

2

Được rồi, đây là toàn bộ thực hiện:

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> 

PHP Mã

Bây giờ bạn có một địa chỉ URL và tiêu đề từ chữ số sau đó bạn có thể sử dụng mã dưới đây:

$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); 
Các vấn đề liên quan