Php 当wordpress帖子发布时,如何使用twitteroauth进行推文?
我试图在发布帖子时发推特。在此之前,我在一个可以提交表单的前端页面中实现了 提交表单时,它会在推特上发送信息。很好 所有的twitteroauth文件都在我的Php 当wordpress帖子发布时,如何使用twitteroauth进行推文?,php,wordpress,twitter,oauth,Php,Wordpress,Twitter,Oauth,我试图在发布帖子时发推特。在此之前,我在一个可以提交表单的前端页面中实现了 提交表单时,它会在推特上发送信息。很好 所有的twitteroauth文件都在我的子主题文件夹中 现在我想在从管理面板提交帖子时发tweet 所以我尝试了以下代码: <?php /* Tweet when the post is published */ add_action('future_to_publish', 'send_emails_on_new_event'); add_action('new_to
子主题
文件夹中
现在我想在从管理面板提交帖子时发tweet
所以我尝试了以下代码:
<?php
/* Tweet when the post is published */
add_action('future_to_publish', 'send_emails_on_new_event');
add_action('new_to_publish', 'send_emails_on_new_event');
add_action('draft_to_publish' ,'send_emails_on_new_event');
add_action('auto-draft_to_publish' ,'send_emails_on_new_event');
function send_emails_on_new_event($post)
{
require "autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
$consumerKey = "My Consumer Key"; // Consumer Key
$consumerSecret = "My Consumer Secret"; // Consumer Secret
$accessToken = "My Access Token"; // Access Token
$accessTokenSecret = "My Access Token Secret"; // Access Token Secret
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
/* Media - 2 photos */
$media1 = $connection->upload('media/upload', array('media' => 'https://pbs.twimg.com/media/CTBv1rCVAAEwKjS.jpg'));
$media2 = $connection->upload('media/upload', array('media' => 'https://pbs.twimg.com/media/CTBv1rCVAAEwKjS.jpg'));
$parameters = array(
'status' => 'Tweeted by the post is published',
'media_ids' => implode(',', array($media1->media_id_string, $media2->media_id_string)),
);
$result = $connection->post('statuses/update', $parameters);
if ($connection->getLastHttpCode() == 200) {
echo 'Tweeted successfully';
} else {
echo 'Something went wrong';
}
}
?>
当我使用use
时,我想我必须做些别的事情。那是什么?
我怎样才能解决这个问题?嘿,我知道已经太晚了,但你知道答案了吗?
require "autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;