【发布时间】:2019-02-09 11:01:04
【问题描述】:
我开发了一个 API 功能,无需登录即可将内容发布到 Instagram,问题是图像必须在本地(在计算机中,d:\..e:\..等)我想上传图像例如来自 url 文件 (http://example.com/images/pict1.jpg) 但仅适用于本地文件,这里是代码:
set_time_limit(0);
date_default_timezone_set('UTC');
require __DIR__.'../../../vendor/autoload.php';
/////// CONFIG ///////
$username = 'instagram username';
$password = 'instagram pass';
$debug = false;
$truncatedDebug = false;
//////////////////////
/////// MEDIA ////////
$photoFilename = '';
$captionText = '';
//////////////////////
$ig = new \InstagramAPI\Instagram($debug, $truncatedDebug);
try {
$ig->login($username, $password);
} catch (\Exception $e) {
//echo 'Something went wrong: '.$e->getMessage()."\n";
exit(0);
}
try {
$photo = new \InstagramAPI\Media\Photo\InstagramPhoto($photoFilename);
$ig->timeline->uploadPhoto($photo->getFile(), ['caption' => $captionText]);
} catch (\Exception $e) {
//echo 'Something went wrong: '.$e->getMessage()."\n";
}
感谢阅读,希望有解决这个问题的办法。
【问题讨论】:
-
用
file_get_contents读取文件存储在服务器上,上传,删除?
标签: php codeigniter instagram