Add/Embed Instagram 帖子至 Laravel 7

Add/Embed Instagram Posts To Laravel 7

我想要什么: 我正在使用 Laravel 7 为我的客户创建一个博客。他想通过类似于旋转木马的方式在他的 Instagram post 中添加一个包含 link 的部分,这样,当他 post 一个新的 Instagram post 时,该网站将自动更新。

我做了什么:

  1. 我去了 developers.facebook.com,创建了一个新应用并设置了 Instagram Basic Display ,在那里我获得了 Instagram 应用 ID、秘密和名称。
  2. 为本地主机添加了客户端 OAuth 设置,它迫使我添加 ssl (https) 我知道这行不通,稍后我会将其更改为实际域,我希望有一种方法来测试它也在本地主机上。 .
  3. 我添加了 Instagram 测试器并授权它并生成了一个访问令牌。
  4. 我从 github-repo
  5. 安装了 composer require dymantic/laravel-instagram-feed
  6. 我 运行 命令 php artisan vendor:publish 显示了这些选项
Which provider or tag's files would you like to publish?:
  [0 ] Publish files from all providers and tags listed below
  [1 ] Provider: Dymantic\InstagramFeed\InstagramFeedServiceProvider
  [2 ] Provider: Facade\Ignition\IgnitionServiceProvider

所以我输入了1我运行php artisan migrate;它创建了以下文件 我将客户端 ID 和密码更新为第一张照片中显示的数据我 linked:

// 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,
];
  1. 我在 运行 命令 php artisan instagram-feed:profile my-insta-username 之后添加了以下特征:
<?php

namespace App\Traits;

use \Dymantic\InstagramFeed\Profile;

trait Instagram
{
    public static function feed()
    {
        $profile = Profile::where('username', 'my-insta-username')->first();

        $feed = $profile->feed();
        
        dd($profile);
    }
}

结果和结论: 显然这没有用,函数 $profile->feed(); 未知,因为配置文件只是一个我们无权访问的集合Instagram API 还没有。

问题: 任何获取所需数据的想法,即使我可以使用 curl 请求获得相同的结果,我如何才能从我已经做过的事情中受益会好的??

谢谢你:)

如果您想实现的是将您的 Ig 提要图像嵌入到轮播中,我建议您使用 postaddic/instragram 程序包 (https://github.com/postaddictme/instagram-php-scraper)。

使用此包,您可以像这样轻松获取图像的 URL:

$instagram  = Instagram::withCredentials('login', 'password', new Psr16Adapter('Files'));
$instagram->login();
$instagram->saveSession();

$posts  = $instagram->getFeed();

foreach ($posts as $post){
    echo $post->getImageHighResolutionUrl()."\n";
}

如果你想测试,我发现这是获取 public 个帐户的最简单方法:

$instagram = new \InstagramScraper\Instagram();

// For getting information about account you don't need to auth:

$account = $instagram->getAccount('neymarjr'); 

如果配置文件 public 更好,因为您可以使用不需要凭据进行身份验证的方法。

不需要直接从 Ig API 嵌入照片的麻烦。