0

我正在尝试在我的网站中实现sketchfab api。我从他们的网站获得了代码和访问令牌,我实现了一切,但是当我执行代码时,我得到一个空白屏幕。问题是什么?

第一个问题是 curl,我通过转到 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

?>
4

1 回答 1

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"
}

如果您对此有疑问,请尝试在命令行中打印调用结果。

于 2013-04-19T13:58:58.900 回答