Php 使用abraham twitteroauth库自动登录Twitter
我有twitter用户名和密码。我想要的是,当客户端从管理端添加任何新文章时,我希望它的url是自动twit。我不想在客户每次添加文章时都打扰他登录twitter。有没有办法使用Abraham twitteroauth库自动登录。谢谢Twitter首先需要授权客户端应用程序,然后才能在某些情况下(即发布新文章)自动推特。对于一个详细的描述,你可以看看我创造的这个。它使用亚伯拉罕的Twitter oAuth库。在亚伯拉罕的图书馆档案中也有一个清晰的例子,可以稍微澄清一下这一点 另一方面,您用于客户站点的CMS/博客应该提供挂钩(回调),以便知道何时创建帖子,从而相应地调用Tweet方法 Chyrp的链接Twitter模块示例: 1) 使用Twitter授权:Php 使用abraham twitteroauth库自动登录Twitter,php,twitter,Php,Twitter,我有twitter用户名和密码。我想要的是,当客户端从管理端添加任何新文章时,我希望它的url是自动twit。我不想在客户每次添加文章时都打扰他登录twitter。有没有办法使用Abraham twitteroauth库自动登录。谢谢Twitter首先需要授权客户端应用程序,然后才能在某些情况下(即发布新文章)自动推特。对于一个详细的描述,你可以看看我创造的这个。它使用亚伯拉罕的Twitter oAuth库。在亚伯拉罕的图书馆档案中也有一个清晰的例子,可以稍微澄清一下这一点 另一方面,您用于客户
static function admin_chweet_auth($admin) {
if (!Visitor::current()->group->can("change_settings"))
show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings."));
# If the oauth_token is old redirect
if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token'])
Flash::warning(__("Old token. Please refresh the page and try again."), "/admin/?action=chweet_settings");
# New TwitteroAuth object with app key/secret and token key/secret from SESSION
$tOAuth = new TwitterOAuth(C_KEY, C_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$access_token = $tOAuth->getAccessToken($_REQUEST['oauth_verifier']);
# Save access tokens locally for future tweeting.
$config = Config::current();
$config->set("chweet_oauth_token", $access_token["oauth_token"]);
$config->set("chweet_oauth_secret", $access_token["oauth_token_secret"]);
$config->set("chweet_user_id", $access_token["user_id"]);
$config->set("chweet_username", $access_token["screen_name"]);
unset($_SESSION['oauth_token']);
unset($_SESSION['oauth_token_secret']);
if (200 == $tOAuth->http_code)
Flash::notice(__("Chweet was successfully Authorized to Twitter."), "/admin/?action=chweet_settings");
else
Flash::warning(__("Chweet couldn't be authorized."), "/admin/?action=chweet_settings");
}
2) add\u post(触发器)
3) Tweet-it方法(截断)
public function add_post($post) {
fallback($chweet, (int) !empty($_POST['chweet']));
SQL::current()->insert("post_attributes",
array("name" => "tweeted",
"value" => $chweet,
"post_id" => $post->id));
if ($chweet and $post->status == "public")
$this->tweet_post($post);
}
public function tweet_post($post) {
$tOAuth = new TwitterOAuth(C_KEY, C_SECRET, $config->chweet_oauth_token, $config->chweet_oauth_secret);
$user = $tOAuth->get("account/verify_credentials");
$response = $tOAuth->post("statuses/update", array("status" => $status));
return $response;
}