liamcottle / instagram-sdk-php
这是一个PHP中Instagram私有API的非官方SDK
这个包的规范仓库似乎已丢失,因此该包已被冻结。
Requires
- php: >=5.3.0
- ext-curl: *
- netresearch/jsonmapper: ^0.11.0
- php-curl-class/php-curl-class: ^4.11
- ramsey/uuid: ^3.4
This package is auto-updated.
Last update: 2019-07-07 07:11:03 UTC
README
这是一个PHP中Instagram私有API的非官方SDK
动机
我决定构建这个项目,因为我在Instagram私有API中发现的大多数库都不是基于OOP的,并且难以使用。
捐赠
如果你喜欢这个项目,请考虑向我的咖啡瘾基金捐赠,这样我就可以继续提交代码!
Paypal: 捐赠
Bitcoin: 1814x9kioBxPDBCQx8oaty7e6Z3DAosucd
安装
Composer
composer require liamcottle/instagram-sdk-php
require("../vendor/autoload.php"); $instagram = new \Instagram\Instagram();
如果你想要测试master分支中的代码,该分支尚未作为发布版本推送,可以使用dev-master
。
composer require liamcottle/instagram-sdk-php dev-master
没有Composer?
什么?!在这里获取: https://getcomposer.org.cn/
示例
示例可以在examples文件夹中看到。
使用
登录
阅读:会话管理,以避免在每次脚本中调用login
。
$instagram->login("username", "password");
时间轴Feed
$maxId
:string
(可选) 用于分页
$instagram->getTimelineFeed($maxId);
用户Feed
$userId
:string|User
要获取Feed的用户或用户ID$maxId
:string
(可选) 用于分页
$instagram->getUserFeed($userId, $maxId);
我的用户Feed
$maxId
:string
(可选) 用于分页
$instagram->getMyUserFeed($maxId);
点赞Feed
$maxId
:string
(可选) 用于分页
$instagram->getLikedFeed($maxId);
标签Feed
$tag
:string
标签$maxId
:string
(可选) 用于分页
$instagram->getTagFeed($tag, $maxId);
位置Feed
$locationId
:string|Location
要获取Feed的位置或位置ID$maxId
:string
(可选) 用于分页
$instagram->getLocationFeed($locationId, $maxId);
用户标签Feed
$userId
:string|User
要获取标签Feed的用户或用户ID$maxId
:string
(可选) 用于分页
$instagram->getUserTagsFeed($userId, $maxId);
喜欢媒体
$mediaId
:string|FeedItem
喜欢的FeedItem或FeedItem Id
$instagram->likeMedia($mediaId);
取消喜欢媒体
$mediaId
:string|FeedItem
要取消喜欢的FeedItem或FeedItem Id
$instagram->unlikeMedia($mediaId);
删除媒体
$mediaId
:string|FeedItem
要删除的FeedItem或FeedItem Id$mediaType
:int
媒体类型(在DeleteMediaRequest
类中可用的常量)
$instagram->deleteMedia($mediaId, $mediaType);
在媒体上评论
$mediaId
:string|FeedItem
要评论的FeedItem或FeedItem Id$comment
:string
评论
$instagram->commentOnMedia($mediaId, $comment);
获取媒体评论
$mediaId
:string|FeedItem
获取评论的媒体FeedItem或FeedItem Id$maxId
:string
(可选) 用于分页
$instagram->getMediaComments($mediaId, $maxId);
删除媒体评论
$mediaId
:string|FeedItem
要删除评论的FeedItem或FeedItem Id$commentIds
:array
要删除的评论Id数组
$instagram->deleteCommentsFromMedia($mediaId, $commentIds);
用户信息
$userId
:string|User
用户或用户Id以获取信息
$instagram->getUserInfo($userId);
用户关注者
$userId
:string|User
获取关注者的用户或用户Id$maxId
:string
(可选) 用于分页
$instagram->getUserFollowers($userId, $maxId);
用户关注列表
$userId
:string|User
获取关注的用户或用户Id$maxId
:string
(可选) 用于分页
$instagram->getUserFollowing($userId, $maxId);
地理位置媒体
$userId
:string|User
获取地理位置媒体的用户或用户Id
$instagram->getUserMap($userId);
媒体信息
$mediaId
:string|FeedItem
获取信息的FeedItem或FeedItem Id
$instagram->getMediaInfo($mediaId);
当前用户账户
$instagram->getCurrentUserAccount();
编辑用户资料
$firstname
:string
名字$email
:string
邮箱$phoneNumber
:string
电话号码$gender
:int
性别(在User
类中可用的常量)$biography
:string
: 个人简介$externalUrl
:string
外部链接
$instagram->editUserProfile($firstname, $email, $phoneNumber, $gender, $biography, $externalUrl);
设置账户公开
$instagram->setAccountPublic();
设置账户私有
$instagram->setAccountPrivate();
显示好友关系
$userId
:string|User
显示用户或用户Id之间的好友关系
$instagram->showFriendship($userId);
关注用户
$userId
:string|User
要关注的用户或用户Id
$instagram->followUser($userId);
取消关注用户
$userId
:string|User
要取消关注的用户或用户Id
$instagram->unfollowUser($userId);
阻止用户
$userId
:string|User
要阻止的用户或用户Id
$instagram->blockUser($userId);
解除阻止用户
$userId
:string|User
要解除阻止的用户或用户Id
$instagram->unblockUser($userId);
搜索标签
$query
:string
要搜索的标签
$instagram->searchTags($query);
搜索用户
$query
:string
要搜索的用户
$instagram->searchUsers($query);
搜索地点(Facebook)
$query
:string
要搜索的地点
$instagram->searchFacebookPlaces($query);
$latitude
:string
纬度$longitude
:string
经度
$instagram->searchFacebookPlacesByLocation($latitude, $longitude);
更改个人资料图片
$path
:string
要上传的个人资料图片的文件路径
$instagram->changeProfilePicture($path);
移除个人资料图片
$instagram->removeProfilePicture();
发布照片
$path
:string
要发布的照片的文件路径$caption
:string
这张照片的说明
$instagram->postPhoto($path, $caption);
编辑媒体
$mediaId
:string|FeedItem
要编辑的FeedItem或FeedItem ID$caption
:string
这段媒体的说明
$instagram->editMedia($mediaId, $caption);
通过用户名获取用户
$username
:string
要查找的用户名
$instagram->getUserByUsername($username);
注销
$instagram->logout();
会话管理
为了避免每次都登录,您可以使用saveSession
和initFromSavedSession
方法。
脚本1
//Login $instagram->login("username", "password"); //Serialize the Session into a JSON string $savedSession = $instagram->saveSession(); //Store $savedSession in Database, or Cookie etc
脚本2
//Load $savedSession from Database or Cookie etc $savedSession = ...; //Init from Saved Session $instagram->initFromSavedSession($savedSession); //Session is Restored, do something! $instagram-> ...;
附加功能
分页
一些Instagram端点返回分页数据。
要访问数据下一页,您需要从响应对象中获取下一个最大ID,并将其作为nextMaxId
参数传递到相同的方法中。
示例
//Get TimelineFeed $timelineFeed = $instagram->getTimelineFeed(); //This will be null if there are no more pages. $nextMaxId = $timelineFeed->getNextMaxId(); //We have another page of Items if($nextMaxId != null){ //Get the next page. $timelineFeed = $instagram->getTimelineFeed($nextMaxId); }
代理
在您的服务器和Instagram API之间使用代理
$instagram->setProxy("127.0.0.1:8888");
可选的用户名/密码身份验证
$instagram->setProxy("127.0.0.1:8888", "proxyUsername", "proxyPassword");
启用或禁用对等验证,用于与Charles Proxy等测试。
$instagram->setVerifyPeer(false);
待办事项
- 收件箱
- 直接分享
- 最近活动
- 注册新账户
- 上传和发布视频
贡献
如果您想为此项目做出贡献,请随时提交pull请求。
在这样做之前,请查看问题,看看您想要贡献的功能是否已在开发中。
许可
MIT
法律
"Instagram"是Instagram Inc.的版权。
本项目与Instagram Inc.或其任何附属公司或子公司无关,未经授权、维护、赞助或认可。
我,项目所有者和创建者,不对使用本项目的任何法律问题负责。自行承担风险。