Home php教程 php手册 新浪微博开放平台PHP 类 WeiboClient 说明

新浪微博开放平台PHP 类 WeiboClient 说明

Jun 21, 2016 am 08:52 AM
access function nbsp param public

在初步掌握微博应用开发的流程后,建议通读一遍weibooauth.php中的代码,优先读class WeiboClient中公共方法的定义。这些方法都是直接操作微博和用户的,清楚有哪些方法,其调用接口、默认参数等。 

 

  本文提供了class WeiboClient中公共方法的说明。这些方法用于直接操作微博和用户的,需要很熟练地使用,熟知每个方法的名称、参数和返回值类型。大多函数的返回值为array,还需要通过API文档知道对应array中各字段的信息。

     /**
     * 发表图片微博
     * @access public
     * @param string $text 要更新的微博信息。
     * @param string $text 要发布的图片路径,支持url。[只支持png/jpg/gif三种格式,增加格式请修改get_image_mime方法]
     * @return array
     */
    function upload( $text , $pic_path )

 

据此,我们知道发图片微博的代码应该包括:

(1)创建WeiboClient类的对象实例(该实例来自于授权,一段程序中多种功能可以共用一个实例);

  (2)准备微博信息及图片url;

  (3)用upload方法发送;

  (4)利用返回的array完成后续处理。

$c = new WeiboClient( WB_AKEY ,
                      WB_SKEY ,
                     $_SESSION['last_key']['oauth_token'] ,
                     $_SESSION['last_key']['oauth_token_secret']  );
$t=’新微博’;
$p=’ ;
$rr = $c ->upload( $t, $p );
echo "

发送完成

" ;
}
?>

 

 


  下面是class WeiboClient中公共方法的说明。

 


class WeiboClient
{
    /**
     * 构造函数
     *
     * @access public
     * @param mixed $akey 微博开放平台应用APP KEY
     * @param mixed $skey 微博开放平台应用APP SECRET
     * @param mixed $accecss_token OAuth认证返回的token
     * @param mixed $accecss_token_secret OAuth认证返回的token secret
     * @return void
     */
    function __construct( $akey , $skey ,$accecss_token , $accecss_token_secret )
 
    /**
     * 最新公共微博
     *
     * @access public
     * @return array
     */
    function public_timeline()
 
    /**
     * 最新关注人微博
     *
     * @access public
     * @return array
     */
    function friends_timeline()
 
 
    /**
     * 最新关注人微博
     *
     * @access public
     * @return array
     */
    function home_timeline()
 
    /**
     * 最新@用户的
     *
     * @access public
     * @param int $page 返回结果的页序号。
     * @param int $count 每次返回的最大记录数(即页面大小),不大于200,默认为20。
     * @return array
     */
    function mentions( $page = 1 , $count = 20)
 
 
    /**
     * 发表微博
     *
     * @access public
     * @param mixed $text 要更新的微博信息。
     * @return array
     */
    function update( $text )
 
  
    /**
     * 发表图片微博
     *
     * @access public
     * @param string $text 要更新的微博信息。
     * @param string $text 要发布的图片路径,支持url。[只支持png/jpg/gif三种格式,增加格式请修改get_image_mime方法
     ]
     * @return array
     */
    function upload( $text , $pic_path )
 
 
    /**
     * 获取单条微博
     *
     * @access public
     * @param mixed $sid 要获取已发表的微博ID
     * @return array
     */
    function show_status( $sid )
 
    /**
     * 删除微博
     *
     * @access public
     * @param mixed $sid 要删除的微博ID
     * @return array
     */
    function delete( $sid )
 
 
    /**
     * 删除微博
     *
     * @access public
     * @param mixed $sid 要删除的微博ID
     * @return array
     */
    function destroy( $sid )
 
 
    /**
     * 个人资料
     *
     * @access public
     * @param mixed $uid_or_name 用户UID或微博昵称。
     * @return array
     */
    function show_user( $uid_or_name = null )
 
    /**
     * 关注人列表
     *
     * @access public
     * @param bool $cursor 单页只能包含100个关注列表,为了获取更多则cursor默认从-1开始,通过增加或减少cursor来获
     取更多的关注列表
     * @param bool $count 每次返回的最大记录数(即页面大小),不大于200,默认返回20
     * @param mixed $uid_or_name 要获取的 UID或微博昵称
     * @return array
     */
    function friends( $cursor = false , $count= false , $uid_or_name = null )
 
 
    /**
     * 粉丝列表
     *
     * @access public
     * @param bool $cursor 单页只能包含100个粉丝列表,为了获取更多则cursor默认从-1开始,通过增加或减少cursor来获
     取更多的粉丝列表
     * @param bool $count 每次返回的最大记录数(即页面大小),不大于200,默认返回20。
     * @param mixed $uid_or_name  要获取的UID或微博昵称
     * @return array
     */
    function followers( $cursor = false ,$count = false , $uid_or_name = null )
 
 
    /**
     * 关注一个用户
     *
     * @access public
     * @param mixed $uid_or_name 要关注的用户UID或微博昵称
     * @return array
     */
    function follow( $uid_or_name )
 
 
    /**
     * 取消关注某用户
     *
     * @access public
     * @param mixed $uid_or_name 要取消关注的用户UID或微博昵称
     * @return array
     */
    function unfollow( $uid_or_name )
 
 
    /**
     * 返回两个用户关系的详细情况
     *
     * @access public
     * @param mixed $uid_or_name 要判断的用户UID
     * @return array
     */
    function is_followed( $uid_or_name )
 
 
    /**
     * 用户发表微博列表
     * 
     * @access public
     * @param int $page 页码
     * @param int $count 每次返回的最大记录数,最多返回200条,默认20。
     * @param mixed $uid_or_name 指定用户UID或微博昵称
     * @return array
     */
    function user_timeline( $page = 1 , $count= 20 , $uid_or_name = null )
 
 
    /**
     * 获取私信列表
     *
     * @access public
     * @param int $page 页码
     * @param int $count 每次返回的最大记录数,最多返回200条,默认20。
     * @return array
     */
    function list_dm( $page = 1 , $count =20  )
 
 
    /**
     * 发送的私信列表
     *
     * @access public
     * @param int $page 页码
     * @param int $count 每次返回的最大记录数,最多返回200条,默认20。
     * @return array
     */
    function list_dm_sent( $page = 1 , $count =20 )
 
 
    /**
     * 发送私信
     *
     * @access public
     * @param mixed $uid_or_name UID或微博昵称
     * @param mixed $text 要发生的消息内容,文本大小必须小于300个汉字。
     * @return array
     */
    function send_dm( $uid_or_name , $text )
 
 
    /**
     * 删除一条私信
     *
     * @access public
     * @param mixed $did 要删除的私信主键ID
     * @return array
     */
    function delete_dm( $did )
 
 
    /**
     * 转发一条微博信息。
     *
     * @access public
     * @param mixed $sid 转发的微博ID
     * @param bool $text 添加的转发信息。
     * @return array
     */
    function repost( $sid , $text = false )
 
 
    /**
     * 对一条微博信息进行评论
     *
     * @access public
     * @param mixed $sid 要评论的微博id
     * @param mixed $text 评论内容
     * @param bool $cid 要评论的评论id
     * @return array
     */
    function send_comment( $sid , $text , $cid= false )
 
 
    /**
     * 发出的评论
     *
     * @access public
     * @param int $page 页码
     * @param int $count 每次返回的最大记录数,最多返回200条,默认20。
     * @return array
     */
    function comments_by_me( $page = 1 , $count= 20 )
 
 
    /**
     * 最新评论(按时间)
     *
     * @access public
     * @param int $page 页码
     * @param int $count 每次返回的最大记录数,最多返回200条,默认20。
     * @return array
     */
    function comments_timeline( $page = 1 ,$count = 20 )
 
 
    /**
     * 单条评论列表(按微博)
     *
     * @access public
     * @param mixed $sid 指定的微博ID
     * @param int $page 页码
     * @param int $count 每次返回的最大记录数,最多返回200条,默认20。
     * @return array
     */
    function get_comments_by_sid( $sid , $page= 1 , $count = 20 )
 
 
    /**
     * 批量统计微博的评论数,转发数,一次请求最多获取100个。
     *
     * @access public
     * @param mixed $sids 微博ID号列表,用逗号隔开
     * @return array
     */
    function get_count_info_by_ids( $sids )
 
 
    /**
     * 对一条微博评论信息进行回复。
     *
     * @access public
     * @param mixed $sid 微博id
     * @param mixed $text 评论内容。
     * @param mixed $cid 评论id
     * @return array
     */
    function reply( $sid , $text , $cid )
 
 
    /**
     * 返回用户的发布的最近20条收藏信息,和用户收藏页面返回内容是一致的。
     *
     * @access public
     * @param bool $page 返回结果的页序号。
     * @return array
     */
    function get_favorites( $page = false )
 
 
    /**
     * 收藏一条微博信息
     *
     * @access public
     * @param mixed $sid 收藏的微博id
     * @return array
     */
    function add_to_favorites( $sid )
 
 
    /**
     * 删除微博收藏。
     *
     * @access public
     * @param mixed $sid 要删除的收藏微博信息ID.
     * @return array
     */
    function remove_from_favorites( $sid )
  
  
    function verify_credentials()
 
    /**
     * 修改头像
     *
     */   
    function update_avatar( $pic_path )
 
} 



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the benefits of multithreading in c#? What are the benefits of multithreading in c#? Apr 03, 2025 pm 02:51 PM

The advantage of multithreading is that it can improve performance and resource utilization, especially for processing large amounts of data or performing time-consuming operations. It allows multiple tasks to be performed simultaneously, improving efficiency. However, too many threads can lead to performance degradation, so you need to carefully select the number of threads based on the number of CPU cores and task characteristics. In addition, multi-threaded programming involves challenges such as deadlock and race conditions, which need to be solved using synchronization mechanisms, and requires solid knowledge of concurrent programming, weighing the pros and cons and using them with caution.

How to use sql if statement How to use sql if statement Apr 09, 2025 pm 06:12 PM

SQL IF statements are used to conditionally execute SQL statements, with the syntax as: IF (condition) THEN {statement} ELSE {statement} END IF;. The condition can be any valid SQL expression, and if the condition is true, execute the THEN clause; if the condition is false, execute the ELSE clause. IF statements can be nested, allowing for more complex conditional checks.

Unable to log in to mysql as root Unable to log in to mysql as root Apr 08, 2025 pm 04:54 PM

The main reasons why you cannot log in to MySQL as root are permission problems, configuration file errors, password inconsistent, socket file problems, or firewall interception. The solution includes: check whether the bind-address parameter in the configuration file is configured correctly. Check whether the root user permissions have been modified or deleted and reset. Verify that the password is accurate, including case and special characters. Check socket file permission settings and paths. Check that the firewall blocks connections to the MySQL server.

How to avoid third-party interfaces returning 403 errors in Node environment? How to avoid third-party interfaces returning 403 errors in Node environment? Apr 01, 2025 pm 02:03 PM

How to avoid the third-party interface returning 403 error in the Node environment. When calling the third-party website interface using Node.js, you sometimes encounter the problem of returning 403 error. �...

How to configure zend for apache How to configure zend for apache Apr 13, 2025 pm 12:57 PM

How to configure Zend in Apache? The steps to configure Zend Framework in an Apache Web Server are as follows: Install Zend Framework and extract it into the Web Server directory. Create a .htaccess file. Create the Zend application directory and add the index.php file. Configure the Zend application (application.ini). Restart the Apache Web server.

How to solve the 'Network Error' caused by Vue Axios across domains How to solve the 'Network Error' caused by Vue Axios across domains Apr 07, 2025 pm 10:27 PM

Methods to solve the cross-domain problem of Vue Axios include: Configuring the CORS header on the server side using the Axios proxy using JSONP using WebSocket using the CORS plug-in

How to efficiently obtain component_verify_ticket in EasyWechat 5.5? How to efficiently obtain component_verify_ticket in EasyWechat 5.5? Apr 01, 2025 pm 12:42 PM

Get ComponentVerify in EasyWechat5.5...

How to use Debian Apache logs to improve website performance How to use Debian Apache logs to improve website performance Apr 12, 2025 pm 11:36 PM

This article will explain how to improve website performance by analyzing Apache logs under the Debian system. 1. Log Analysis Basics Apache log records the detailed information of all HTTP requests, including IP address, timestamp, request URL, HTTP method and response code. In Debian systems, these logs are usually located in the /var/log/apache2/access.log and /var/log/apache2/error.log directories. Understanding the log structure is the first step in effective analysis. 2. Log analysis tool You can use a variety of tools to analyze Apache logs: Command line tools: grep, awk, sed and other command line tools.

See all articles