2013-04-17 67 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)。 –