Twitter Bot PHP
1.0.0
Twitter机器人使用PHP自动更新状态。
在Twitter开发人员帐户中注册应用程序
从“开发人员”页面注册一个应用程序。记住永远不要透露您的消费者秘密。现在,您拥有消费者密钥,消费者秘密,访问令牌和访问令牌秘密。
下载Codebird-php
使用Codebird连接到Twitter REST API,流媒体API,Collections API,TON(对象嵌套)API和Twitter ADS API中的API,都只使用一个库。 Codebird支持完整的3向OAuth以及仅应用程序的Auth。
可以从这里下载或这里下载
发送消息:将消息发送到组或频道:
$ ApiKey = < API_KEY >;
$ ApiSecretKey = < API_SECRET_KEY >;
$ AccessToken = < ACCESS_TOKEN >;
$ AccessTokenSecret = < ACCESS_TOKEN_SECRET >;
// add the codebird library
require_once ( ' codebird/src/codebird.php ' );
Codebird Codebird:: setConsumerKey ( $ ApiKey , $ ApiSecretKey );
$ cb = Codebird Codebird:: getInstance ();
$ cb -> setToken ( $ AccessToken , $ AccessTokenSecret );
//build an array of images to send to twitter
$ reply = $ cb -> media_upload ( array (
' media ' => < IMAGE_URL > or < IMAGE_URI >
));
//upload the file to your twitter account
$ mediaID = $ reply -> media_id_string ;
// implode mandatory only for multile media uploads
$ params = array (
' status ' => " #message " ,
' media_ids ' => implode ( ' , ' , [ $ mediaID ]) // optional
);
//post the tweet with codebird
$ reply = $ cb -> statuses_update ( $ params );
function get_content ( $ URL )
{
$ ch = curl_init ();
curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt ( $ ch , CURLOPT_URL , $ URL );
$ data = curl_exec ( $ ch );
curl_close ( $ ch );
return $ data ;
}
如果您欣赏我的工作,请考虑给我一杯☕以让我充电吗?由贝宝
Copyright 2020 MyInnos
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.