jacob-ian / instagram-feed
使用旧版Instagram API的简单Instagram信息流
Requires
- php: >=7.2.0
Requires (Dev)
- php: >=7.2.0
This package is not auto-updated.
Last update: 2024-09-29 05:15:01 UTC
README
使用旧API的Instagram信息流。它会在您的web服务器中缓存帖子数据,并使用MySQL数据库存储元数据以最大化加载速度。
要求
- 一个与要显示的帐户连接的Instagram访问令牌。注意:帐户必须是公开的。
- PHP 7.2+
用法
-
通过Composer将此存储库包含到您的项目中(jacob-ian/instagram-feed)。
-
创建一个MySQL数据库来存储数据
CREATE DATABASE instagram
\JacobIan\InstagramFeed\instagramFetch
类将自动创建表并填充它。 -
设置一个cron-job,指向包含以下内容的PHP文件
require_once('instagram-feed/src/instagramFetch.class.php'); $instagramData = new \JacobIan\InstagramFeed\instagramFetch($database, $accesstoken, $cachepath); $instagramData->fetch();
可以将
require_once()
替换为自动加载器。其中
-
$database
应是一个具有以下结构的数组$database = array( "username"=>"[username]", "password"=>"[password]", "host"=>"[host]", "database"=>"instagram" );
-
$accesstoken
是一个字符串,包含与您要显示的帐户相关的Instagram访问令牌。 -
$cachepath
应是一个字符串,包含您希望在public_html/webroot目录中的Instagram缓存和资源的路径。
此cron job应每15分钟运行一次,但频率可以根据您希望信息流刷新的频率进行调整。
-
-
要创建信息流本身,请在您的PHP网页上使用以下代码
require_once('instagram-feed/src/instagramFeed.class.php'); $instagram_feed = new \JacobIan\InstagramFeed\instagramFeed($database, $count, $style); echo $instagram_feed->feed();
再次,可以将
require_once()
替换为自动加载器。其中
$count
是一个整数,描述要在信息流中显示的最新帖子的数量。Instagram API的限制是20个帖子。$style
是一个字符串,包含每个Instagram帖子所需的CSS样式标签。请参阅以下CSS样式。
-
将以下两行代码添加到包含Instagram信息流的网页的
<head>
中<link rel="stylesheet" type="text/css" href="https://min.gitcdn.xyz/repo/jacob-ian/instagram-feed/master/css/feed.css"/> <script src="https://min.gitcdn.xyz/repo/jacob-ian/instagram-feed/master/js/feed.js"></script>
-
享受吧!
CSS样式
可用的CSS标签有
大小
-
'small'
:带有媒体边框的150x150像素网格大小 -
'medium'
:带有媒体边框的300x300像素网格大小 -
'large'
:带有媒体边框的640x640像素网格大小 -
'small_noframe'
:150x150像素网格大小,无边框 -
'medium_noframe'
:300x300像素网格大小,无边框 -
'large_noframe'
:640x640像素网格大小,无边框
颜色
'dark'
:设置帖子背景颜色为#333
(深灰色)'transparent'
:设置帖子背景颜色为透明'noborder'
:移除帖子的边框- 注意:默认背景颜色为
#fff
(白色)。
间距
'nomargin'
:移除Instagram信息流网格中帖子之间的间隔。
示例样式
'small dark'
:带有颜色#333边框的小网格大小媒体'large_noframe nomargin noborder'
:带有无边框且帖子之间无间隔的大网格大小。这种设置可以轻松使用Masonry JS脚本。
用法
- 只能使用一个大小标签,并且它也是信息流工作的最低要求。
- 在大小标签之后,可以添加其他标签,标签之间用空格分隔。
自定义样式
- 可以通过将它们添加到
$style
字符串中来使用自定义样式,并用空格分隔。 - 要使用自定义大小样式,可以将大小标签替换为自定义字符串。然后,它将被转换为CSS标签
post_[custom]
和media_[custom]
。
注意
\JacobIan\InstagramFeed\instagramFetch
类会自动将'..\assets'
的内容传输到公开可访问的缓存文件夹。\JacobIan\InstagramFeed\instagramFetch
创建一个名为 'details' 的数据库表,包含以下信息- UserID:Instagram 用户 ID
- ProfilePictureURL:您的个人头像的 URL
- ProfilePicturePath:您的个人头像在本地存储的路径
- Followers:您的关注者数量
- Posts:您的帖子数量
- LastUpdate:上一次成功的 instagramFetch 定时任务的时间
- CachePath:存储您的 Instagram 缓存和资源的路径。