2013-04-17 66 views
0

我想在我的網站中實現sketchfab api。我從他們的網站獲得了代碼和訪問令牌,我實現了一切,但是當我執行代碼時,我得到一個空白屏幕。問題是什麼?實現Sketchfab API

第一個問題是捲曲,我啓用它去php.ini文件,但然後這個空白屏幕的問題。

<?php 


$url = "https://api.sketchfab.com/v1/models"; 

$path = "./"; 
$filename = "m.3DS"; 
$description = "Test of the api with a simple model"; 
$token_api = "THE ACCESS TOKEN"; 
$title = "Uber Glasses"; 
$tags = "test collada glasses"; 
$private = 1; 
$password = "Tr0b4dor&3"; 

$data = array(
    "title" => $title, 
    "description" => $description, 
    "fileModel" => "@".$path.$filename, 
    "filenameModel" => $filename, 
    "tags" => $tags, 
    "token" => $token_api, 
    "private" => $private, 
    "password" => $password 
); 

$ch = curl_init(); 
curl_setopt_array($ch, array(
    CURLOPT_RETURNTRANSFER => 1, 
    CURLOPT_URL => $url, 
    CURLOPT_POST => 1, 
    CURLOPT_POSTFIELDS => $data 
)); 

$response = curl_exec($ch); 

curl_close($ch); 

echo $response; // I am trying to echo the response here 

?> 

回答

1

對上傳api的調用將返回一個包含模型id的json。你可以使用這個ID來生成一個url,並再次調用oEmbed api。僞代碼示例:

// your curl setup 
$response = curl_exec($ch); 

// Response 
{success: true, {result: {id: 'xxxxxx'} } when upload OK 
{success: false, error: 'error message'} when upload error 

$id = $response['result']['id']; 
$call= "https://sketchfab.com/oembed?url=https://sketchfab.com/show/" . $id; 
// do another curl call with $call content 
// it will return a response like below but with your model information 
// Response 
{ 
    provider_url: "http://sketchfab.com", 
    provider_name: "Sketchfab", 
    thumbnail_url: "https://sketchfab.com/urls/dGUrytaktlDeNudCEGKk31oTJY/thumbnail_448.png?v=24a1cb0590851ccfeeae01a2ca1eece1", 
    thumbnail_width: "448", 
    thumbnail_height: "280", 
    author_name: "Klaas Nienhuis", 
    author_url: "https://sketchfab.com/klaasnienhuis", 
    title: "Maison d'artiste", 
    html: "<iframe frameborder="0" width="640" height="320" webkitallowfullscreen="true" mozallowfullscreen="true" src="http://sketchfab.com/embed/dGUrytaktlDeNudCEGKk31oTJY?autostart=0&amp;transparent=0&amp;autospin=0&amp;controls=1&amp;watermark=0"></iframe>", 
    width: 640, 
    height: 320, 
    version: "1.0", 
    type: "rich" 
} 

如果您在命令行嘗試打印調用結果時遇到此問題。

+1

此外,請查看[api文檔](http://sketchfab.com/api)。 –