2016-08-25 11 views
2

Google APIコールを処理して特定の変数を保存するphp関数を呼び出すと、私はそれを扱うことができます。 私は以下のコードがうまくいきませんが、私はそれがあなたに何をしたいのかを伝えたいと思っています。 アドバイスをいただきありがとうございます。私のdstOffsetコピー変数に保存Google APIレスポンスをphp変数に保存する

function callGoogleAPI() { 
// calling the fGoggle spi somehow 
https://maps.googleapis.com/maps/api/timezone/json?location=45.908133,-77.047119&timestamp=1472106746 
$dstOffset = dstOffset; 

} 

機能が実行されると、私は値を持たなければならない「3600」。

は、それは非常に基本的な質問です

ビニー

答えて

3

ありがとうございます。あなたはfile_get_contents()またはcurl経由でAPIを呼び出し、json_decode関数でjsonをデコードします。

function callGoogleAPI() { 
    // calling the fGoggle spi somehow 
    $content = file_get_contents('https://maps.googleapis.com/maps/api/timezone/json?location=45.908133,-77.047119&timestamp=1472106746'); 
    $content = json_decode($content, true); 
    $dstOffset = $content['dstOffset']; 
} 
0

PHPでREST APIを使用することは、3段階のプロセスです。

1)あなたがで作業を開始)あなたは

$maps_array = json_decode($content, true); 

3連想配列にJSONオブジェクトを変換)APIをCALおよび可変

$maps_content = file_get_contents('https://maps.googleapis.com/maps/api/timezone/json?location=45.908133,-77.047119&timestamp=1472106746'); 

2で返されたデータを格納しますあなたの配列のデータ

変数がどのように見えるかを見るには、var_dumpを忘れないでください

var_dump($maps_array); 
関連する問題