melsaka/imgur

Imgur API 的 PHP 客户端。可以在您的项目中使用它来与 Imgur API 交互。

v0.2 2021-05-04 03:15 UTC

This package is auto-updated.

Last update: 2024-09-04 10:13:54 UTC


README

这是一个面向对象的 Imgur API PHP 客户端。可以在您的项目中使用它来与 Imgur API 交互。

安装前

您必须在 imgur 上有一个应用程序才能使用此包,并确保获取账户

用户名、client_id、client_secret、access_token、refresh_token.

如果您已经有了应用程序,但不知道如何获取您的 access_tokenrefresh_token,请执行以下操作

访问此 URL https://api.imgur.com/oauth2/authorize?client_id=CLIENT_ID&response_type=token

然后将 CLIENT_ID 替换为您的。

现在您应该被重定向到 imgur,并被要求授权,点击 允许 按钮。

然后您将被重定向到 imgur 主页,URL 应该包含有关

您的 access_tokenrefresh_token 和您的 account_username 的信息。

注意:Imgur 每小时上传限制为 50 张图片,并且每个账户没有上传限制。

更多信息: 我可以上传哪些文件?大小限制是多少?

安装

melsaka/imgur 可以通过 Composer 包管理器安装

composer require melsaka/imgur

使用方法

use Melsaka\Imgur;

$credentials = [
    'username'          => '{{ your username }}',
    'client_id'         => '{{ your client_id }}',
    'client_secret'     => '{{ your client_secret }}',
    'access_token'      => '{{ your access_token }}',
    'refresh_token'     => '{{ your refresh_token }}',
];

$imgur = new Imgur($credentials);

// If $username defaulted to null then the method will return data related to the authenticated user
// $data is an associative array, for example ?query=test should be ['query' => 'test']
// For more info about what kind of $data should be sent check out: https://apidocs.imgur.com 

/** ACCOUNT SECTION **/

// Check the current rate limit status on your application.
$imgur->account()->credits();

// Generates new access token.
$imgur->account()->newToken();

// Request standard user information. 
$imgur->account()->profile($username = null);

// Returns the account settings.
$imgur->account()->settings();

// Updates the account settings.
$imgur->account()->changeSettings($data = []);

// Checks to see if account has verified its email address.
$imgur->account()->isVerified();

// Sends an email to verify that your email is valid to upload to gallery.
$imgur->account()->verify();

// Get the list of available avatars for your account.
$imgur->account()->avatars();

// Get the current account's avatar URL and avatar name.
$imgur->account()->avatar();

// Returns all of the reply notifications for your account.
$imgur->account()->replies($new = true);

// Follows the {tag}.
$imgur->account()->followTag($tag);

// Unfollows the {tag}.
$imgur->account()->unfollowTag($tag);

// Return the images the user has favorited in the gallery.
$imgur->account()->galleryFavorites($username = null, $page = 0, $sort = 'newest');

// Returns the users favorited images.
$imgur->account()->favorites($username = null, $page = 0, $sort = 'newest');

// Return the images a user has submitted to the gallery.
$imgur->account()->submissions($username = null, $page = 0, $sort = 'newest');

// List all accounts being blocked.
$imgur->account()->blocks();

// Determine if the user making the request has blocked a username.
$imgur->account()->blockStatus($username);

// Block a user.
$imgur->account()->block($username);

// Unblock a user.
$imgur->account()->unblock($username);

// Get all the images for the account that is currently authenticated.
$imgur->account()->images($page = 0);

// Return information about a specific image.
$imgur->account()->image($imageId);

// Returns an array of Image IDs that are associated with the authenticated account.
$imgur->account()->imageIds($page = 0);

// Returns the total number of images associated with the account.
$imgur->account()->imageCount();

// Deletes an Image. This requires a delete hash rather than an ID.
$imgur->account()->imageDelete($imageHash);

// Get all the albums associated with the provided username.
$imgur->account()->albums($username = null, $page = 0);

// Get additional information about an album.
$imgur->account()->album($albumHash);

// Return an array of all of the album IDs (hashes).
$imgur->account()->albumIds($username = null, $page = 0);

// Return the total number of albums associated with the account.
$imgur->account()->albumCount($username = null);

// Delete an Album with a given id.
$imgur->account()->albumDelete($albumHash);

// Return the comments the user has created.
$imgur->account()->comments($username = null, $page = 0, $sort = 'newest');

// Return information about a specific comment.
$imgur->account()->comment($commentId);

// Return an array of all of the comment IDs.
$imgur->account()->commentIds($username = null, $page = 0, $sort = 'newest');

// Return a count of all of the comments associated with the account.
$imgur->account()->commentCount($username = null);

// Delete a comment.
$imgur->account()->commentDelete($commentId);

// -----------------------------------------------------------

/** GALLERY SECTION **/

$imgur->gallery()->section($section = 'hot', $sort = 'viral', $page = 0, $window = 'day', $data = []);
// Search the gallery with a given query string.
$imgur->gallery()->search($data, $page = 0, $sort = 'viral', $window = 'day');

// View gallery images for a subreddit
$imgur->gallery()->subreddit($subreddit, $sort = 'time', $page = 0, $window = 'week');

// View a single image in the subreddit.
$imgur->gallery()->subredditImage($subreddit, $imageId);

// Gets a list of default tags
$imgur->gallery()->defaultTags();

// Returns tag metadata, and posts tagged with the tagName provided
$imgur->gallery()->tags($galleryHash);

// Update the tags for a post in the gallery
$imgur->gallery()->tagsUpdate($galleryHash, $data);

// Returns tag metadata, and posts tagged with the tagName provided
$imgur->gallery()->tag($tagName, $page = 0, $sort = 'top', $window = 'day');

// Gets metadata about a tag
$imgur->gallery()->tagInfo($tagName);

// Share an Image to the Gallery.
$imgur->gallery()->imageShare($imageHash, $data);

// Share an Album to the Gallery.
$imgur->gallery()->albumShare($albumHash, $data);

// Remove an image from the public gallery.
$imgur->gallery()->remove($galleryHash);

// Get additional information about an album in the gallery.
$imgur->gallery()->album($albumHash);

// Get additional information about an image in the gallery.
$imgur->gallery()->image($imageHash);

// Report an Image in the gallery
$imgur->gallery()->imageReport($galleryHash, $data);

// Get the vote information about an image.
$imgur->gallery()->voteInfo($galleryHash);

// Vote for an image, up or down vote. Send veto to undo a vote.
$imgur->gallery()->vote($galleryHash, $vote);

// Get comments on an image or album in the gallery.
$imgur->gallery()->comments($galleryHash, $commentSort = 'best');

// Information about a specific comment.
$imgur->gallery()->comment($galleryHash, $commentId);

// Album / Image Comment Creation
$imgur->gallery()->commentCreate($galleryHash, $data)

// -----------------------------------------------------------

/** ALBUM SECTION **/

// Get additional information about an album.
$imgur->album()->info($albumHash);

// Return all of the images in the album.
$imgur->album()->images($albumHash);

// Get information about an image in an album.
$imgur->album()->imageInfo($albumHash, $imageHash);

// Create a new album.
$imgur->album()->create($data);

// Update the information of an album.
$imgur->album()->update($albumHash, $data);

// Delete an album with a given ID.
$imgur->album()->remove($albumHash);

// Favorite an album with a given ID.
$imgur->album()->favorite($albumHash);

// Sets the images for an album, removes all other images and only uses the images in this request.
$imgur->album()->setImages($albumHash, $data);

// Adds the images to an album.
$imgur->album()->addImages($albumHash, $data);

// Delete Images from an album.
$imgur->album()->deleteImages($albumHash, $data);

// -----------------------------------------------------------

/** Image SECTION **/

// Get information about an image.
$imgur->image()->info($imageHash);

// Upload a new image or video.
$imgur->image()->upload($data);

// Updates the title or description of an image.
$imgur->image()->update($imageHash, $data);

// Deletes an image.
$imgur->image()->remove($imageHash);

// Favorite an image with the given ID.
$imgur->image()->favorite($imageHash);

// -----------------------------------------------------------

/** COMMENT SECTION **/

// Get information about a specific comment.
$imgur->comment()->info($commentId);

// Creates a new comment, returns the ID of the comment.
$imgur->comment()->create($data);

// Delete a comment by the given id.
$imgur->comment()->remove($commentId);

// Get the comment with all of the replies for the comment.
$imgur->comment()->replies($commentId);

// Create a reply for the given comment.
$imgur->comment()->createReply($commentId, $data);

// Vote on a comment. The vote parameter can only be set as up, down, or veto.
$imgur->comment()->vote($commentId, $vote);

// Report a comment for being inappropriate.
$imgur->comment()->report($commentId);

请确保查看: Imgur API 文档

许可协议

melsaka/imgur 是一个开源库,许可协议为 MIT 许可协议