Php 向Laravel 7添加/嵌入Instagram帖子
我想要什么:我正在使用Laravel 7为我的客户创建一个博客。他想通过类似旋转木马的方式添加一个包含Instagram帖子链接的部分,这样,当他发布新Instagram帖子时,网站将自动更新 我所做的:Php 向Laravel 7添加/嵌入Instagram帖子,php,instagram,embed,laravel-7,Php,Instagram,Embed,Laravel 7,我想要什么:我正在使用Laravel 7为我的客户创建一个博客。他想通过类似旋转木马的方式添加一个包含Instagram帖子链接的部分,这样,当他发布新Instagram帖子时,网站将自动更新 我所做的: 我访问了developers.facebook.com,创建了一个新的应用程序,并设置了Instagram Basic Display,在那里我获得了Instagram应用程序Id、密码和名称 为localhost添加了客户端OAuth设置,这迫使我添加ssl(https)我知道这不起作用,稍
合成器需要dymantic/laravel instagram订阅源
phpartisanvendor:publish
,它向我显示了这些选项1
我运行的php artisan migrate
;它创建了以下文件我更新了客户端id和机密,以显示在我链接的第一张照片中的数据:
// config/instagram-feed.php
<?php
return [
/*
* The client_id from registering your app on Instagram
*/
'client_id' => 'YOUR INSTAGRAM CLIENT ID',
/*
* The client secret from registering your app on Instagram,
* This is not the same as an access token.
*/
'client_secret' => 'YOUR INSTAGRAM CLIENT SECRET',
/*
* The route that will respond to the Instagram callback during the OAuth process.
* Only enter the path without the leading slash. You need to ensure that you have registered
* a redirect_uri for your instagram app that is equal to combining the
* app url (from config) and this route
*/
'auth_callback_route' => 'instagram/auth/callback',
/*
* On success of the OAuth process you will be redirected to this route.
* You may use query strings to carry messages
*/
'success_redirect_to' => 'instagram-auth-success',
/*
* If the OAuth process fails for some reason you will be redirected to this route.
* You may use query strings to carry messages
*/
'failure_redirect_to' => 'instagram-auth-failure'
/*
* You may filter out video media types by setting this to true. Carousel media
* will become the first image in the carousel, and if there are no images, then
* the entire carousel will be ignored.
*/
'ignore_video' => false,
/*
* You may set an email address below if you wish to be notified of errors when
* attempting to refresh the Instagram feed.
*/
'notify_on_error' => null,
];
结果和结论:显然这不起作用,函数$profile->feed()代码>未知,因为配置文件只是一个集合,我们还没有访问Instagram API的权限
问题:获得所需数据的任何想法如何从我已经做的事情中获益,即使我可以使用curl
请求获得相同的结果,也可以
谢谢:)如果您想要实现的是将Ig提要图像嵌入到旋转木马中,我建议您使用postaddic/instragram
软件包()
使用此软件包,您可以轻松获取图像的URL,如下所示:
$instagram = Instagram::withCredentials('login', 'password', new Psr16Adapter('Files'));
$instagram->login();
$instagram->saveSession();
$posts = $instagram->getFeed();
foreach ($posts as $post){
echo $post->getImageHighResolutionUrl()."\n";
}
如果您想进行测试,我发现这是获取公共帐户的最简单方法:
$instagram = new \InstagramScraper\Instagram();
// For getting information about account you don't need to auth:
$account = $instagram->getAccount('neymarjr');
如果配置文件是公共的,则更好,因为您可以使用不需要您的凭据进行身份验证的方法
不需要直接从Ig API上润色照片带来的麻烦。我不能不登录就这样做吗,毕竟,我获取提要的instagram帐户是一个商业帐户,这是网站所有者的帐户,用户也可能登录到他们的帐户,这可能会打乱会话如果它是一个私人帐户,您只需使用$instagram=\InstagramScraper\Instagram::withCredentials('username','password')$instagram->login()代码>。请从软件包中查找文档。你的用户不需要使用他们的凭据。只有你作为应用程序的所有者才能通过凭据(最好通过env)您将毫无问题地获取图像。此repo没有解释如何安装Class'Phpfastcache\Helper\Psr16Adapter'
,因此即使在我添加了using语句use Phpfastcache\Helper\Psr16Adapter\Psr16Adapter之后,仍然没有找到消息Class'Phpfastcache\Helper\Psr16Adapter'
代码>当我运行Instagram=\Instagram\Instagram::withCredentials(Instagram=\Instagram::withCredentials('username','password')时,我收到的消息参数太少,无法运行InstagramScraper\Instagram::withCredentials()$instagram->login()代码>仅限
$instagram = Instagram::withCredentials('login', 'password', new Psr16Adapter('Files'));
$instagram->login();
$instagram->saveSession();
$posts = $instagram->getFeed();
foreach ($posts as $post){
echo $post->getImageHighResolutionUrl()."\n";
}
$instagram = new \InstagramScraper\Instagram();
// For getting information about account you don't need to auth:
$account = $instagram->getAccount('neymarjr');