Php 实现Sketchfab API

Php 实现Sketchfab API,php,curl,Php,Curl,我正在尝试在我的网站上实现sketchfab api。我从他们的网站上获得了代码和访问令牌,我实现了所有功能,但当我执行代码时,我会看到一个空白屏幕。有什么问题 第一个问题是curl,我通过访问php.ini文件启用了它,但随后出现了这个空白屏幕问题 <?php $url = "https://api.sketchfab.com/v1/models"; $path = "./"; $filename = "m.3DS"; $description = "Test of the api

我正在尝试在我的网站上实现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

?>

对upload 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"
}
//您的curl设置
$response=curl\u exec($ch);
//回应
{success:true,{result:{id:'xxxxxx'}上传时确定
{success:false,上传错误时出错:'错误消息'}
$id=$response['result']['id'];
$call=”https://sketchfab.com/oembed?url=https://sketchfab.com/show/“$id;
//使用$call内容执行另一个curl调用
//它将返回一个如下的响应,但带有您的模型信息
//回应
{
提供程序\u url:“http://sketchfab.com",
提供商名称:“Sketchfab”,
缩略图url:“https://sketchfab.com/urls/dGUrytaktlDeNudCEGKk31oTJY/thumbnail_448.png?v=24a1cb0590851ccfeeae01a2ca1eece1",
缩略图宽度:“448”,
缩略图高度:“280”,
作者姓名:“克拉斯·尼胡斯”,
作者地址:“https://sketchfab.com/klaasnienhuis",
标题:“艺术家之家”,
html:“”,
宽度:640,
身高:320,
版本:“1.0”,
类型:“富”
}
如果您对此有疑问,请尝试在命令行中打印调用结果