alexok / instagram-sdk-php
这是PHP中Instagram私有API的非官方SDK
1.0.4
2016-08-01 05:47 UTC
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 not auto-updated.
Last update: 2024-09-29 04:42:45 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");
时间线流
$maxId
:string
(可选)用于分页
$instagram->getTimelineFeed($maxId);
用户流
$userId
:string|User
获取流的用户或用户ID$maxId
:string
(可选)用于分页
$instagram->getUserFeed($userId, $maxId);
我的用户流
$maxId
:string
(可选)用于分页
$instagram->getMyUserFeed($maxId);
点赞流
$maxId
:string
(可选)用于分页
$instagram->getLikedFeed($maxId);
标签流
$tag
:string
标签$maxId
:string
(可选)用于分页
$instagram->getTagFeed($tag, $maxId);
位置流
$locationId
:string|Location
获取流的地点或地点ID$maxId
:string
(可选)用于分页
$instagram->getLocationFeed($locationId, $maxId);
用户标签流
$userId
:string|User
获取标签流的用户或用户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.或其任何附属公司或子公司无关,未经授权、维护、赞助或支持。
我,项目所有者和创建者,对使用本项目可能产生的任何法律问题不承担责任。自行承担风险。