本文整理汇总了PHP中TwitterAPIExchange::setPostfields方法的典型用法代码示例。如果您正苦于以下问题:PHP TwitterAPIExchange::setPostfields方法的具体用法?PHP TwitterAPIExchange::setPostfields怎么用?PHP TwitterAPIExchange::setPostfields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwitterAPIExchange
的用法示例。
在下文中一共展示了TwitterAPIExchange::setPostfields方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: TwitterAPIExchange
echo "LASTID: " . $lastid . "\r\n";
sleep(30);
while (True) {
$twitter = new TwitterAPIExchange($settings);
$getfield = 'count=200&since_id=' . $lastid;
$twitter = new TwitterAPIExchange($settings);
$res = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
$res = json_decode($res, true);
if (is_array($res)) {
foreach ($res as $r) {
if (!in_array($r["user"]["screen_name"], $ignore)) {
$newTweet = "@" . $r["user"]["screen_name"] . " depends";
if (is_array($r["entities"]["user_mentions"])) {
foreach ($r["entities"]["user_mentions"] as $user) {
$first = true;
if (!in_array($user["screen_name"], $ignore) && $user["screen_name"] != $r["user"]["screen_name"]) {
if ($first) {
$newTweet .= ' \\\\ ' . ($first = false);
}
$newTweet .= "@" . $user["screen_name"] . " ";
}
}
}
$t = new TwitterAPIExchange($settings);
$t->setPostfields(["status" => $newTweet, "in_reply_to_status_id" => $r["id_str"]])->buildOauth("https://api.twitter.com/1.1/statuses/update.json", "POST")->performRequest();
}
$lastid = $r["id_str"];
}
}
sleep(240);
}
示例2: deleteTweet
/**
* Deletes a tweet from our main account (currently hard-coded)
* use as: deleteTweet( '577505080074756097' )
* @param string $tweetId Twitter-namespaced ID of the status to delete
* @return array hash blog back from the Twitter API
*/
function deleteTweet($tweetId)
{
// Returns if we cannot delete this tweet
// Array ( [errors] => Array ( [0] => Array ( [message] => Your credentials do not allow access to this resource [code] => 220 ) ) )
if (!isset($tweetId)) {
return array('errors' => array(array("code" => -1, "message" => 'No message id given?'), array()));
}
// TODO do checks for >140 and being < a few
global $twitterKeys;
$twit = new TwitterAPIExchange($twitterKeys);
$resource = 'https://api.twitter.com/1.1/statuses/destroy/' . $tweetId . '.json';
$fields = array('id' => $tweetId, 'trim_user' => true);
$result = $twit->setPostfields($fields)->buildOauth($resource, 'POST')->performRequest();
// TODO error handling
return json_decode($result, true);
// Good reply: Array ( [created_at] => Fri Mar 27 14:03:21 +0000 2015 [id] => 581456476167888896 [id_str] => 581456476167888896 [text] => @Corben78 🐧 🎮 [source] => SteamLUG.org [truncated] => [in_reply_to_status_id] => [in_reply_to_status_id_str] => [in_reply_to_user_id] => [in_reply_to_user_id_str] => [in_reply_to_screen_name] => [user] => Array ( [id] => 1282779350 [id_str] => 1282779350 [name] => SteamLUG [screen_name] => SteamLUG [location] => [profile_location] => [description] => The Steam Linux User Group! A multilingual community of Linux gamers which aims to be a fun, welcoming space for people of all backgrounds and aptitudes [url] => http://t.co/UV563TiKNB [entities] => Array ( [url] => Array ( [urls] => Array ( [0] => Array ( [url] => http://t.co/UV563TiKNB [expanded_url] => http://steamlug.org [display_url] => steamlug.org [indices] => Array ( [0] => 0 [1] => 22 ) ) ) ) [description] => Array ( [urls] => Array ( ) ) ) [protected] => [followers_count] => 339 [friends_count] => 5 [listed_count] => 23 [created_at] => Wed Mar 20 09:10:33 +0000 2013 [favourites_count] => 30 [utc_offset] => [time_zone] => [geo_enabled] => [verified] => [statuses_count] => 852 [lang] => en [contributors_enabled] => [is_translator] => [is_translation_enabled] => [profile_background_color] => C0DEED [profile_background_image_url] => http://abs.twimg.com/images/themes/theme1/bg.png [profile_background_image_url_https] => https://abs.twimg.com/images/themes/theme1/bg.png [profile_background_tile] => [profile_image_url] => http://pbs.twimg.com/profile_images/3420706844/0169c9632f67b7928a84e723fb460380_normal.png [profile_image_url_https] => https://pbs.twimg.com/profile_images/3420706844/0169c9632f67b7928a84e723fb460380_normal.png [profile_link_color] => 0084B4 [profile_sidebar_border_color] => C0DEED [profile_sidebar_fill_color] => DDEEF6 [profile_text_color] => 333333 [profile_use_background_image] => 1 [default_profile] => 1 [default_profile_image] => [following] => [follow_request_sent] => [notifications] => ) [geo] => [coordinates] => [place] => [contributors] => [retweet_count] => 0 [favorite_count] => 0 [entities] => Array ( [hashtags] => Array ( ) [symbols] => Array ( ) [user_mentions] => Array ( [0] => Array ( [screen_name] => Corben78 [name] => Corben Dallas [id] => 56698692 [id_str] => 56698692 [indices] => Array ( [0] => 0 [1] => 9 ) ) ) [urls] => Array ( ) ) [favorited] => [retweeted] => [lang] => und )
}
示例3: foreach
$requestMethod = 'GET';
while (true) {
foreach ($getfields as $getfield) {
try {
// Perform the request
$twitter = new TwitterAPIExchange($settings);
$twitter2 = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield('?q=' . $getfield)->buildOauth($url, $requestMethod)->performRequest();
$data = json_decode($response);
foreach ($data->statuses as $value) {
$response2 = '';
if (strpos(strtoupper($value->text), 'FOLLOW') == false) {
print $value->text . "\n";
$url2 = "https://api.twitter.com/1.1/statuses/retweet/" . $value->id . ".json";
if (!isset($ids[$value->id])) {
$response2 = $twitter2->setPostfields(array('id' => $value->id))->buildOauth($url2, 'POST')->performRequest();
var_dump($response2);
} else {
print "skip done\n";
}
$ids[$value->id] = true;
} else {
print "skip follow\n";
}
}
print "------------------------------------------------------------------------------------------------\n\n";
sleep(60);
} catch (Exception $e) {
}
}
}
示例4: complaint
$department = $_REQUEST['department'];
$username = $_SESSION['username'];
$selectQuery = "select Dept_ID from department where Dept_Name='{$department}'";
$resultsSet = mysql_query($selectQuery);
$row = mysql_fetch_assoc($resultsSet);
$deptid = $row['Dept_ID'];
$hashtag = '#' . $department;
$insertQuery = "INSERT INTO complaint (Description, Location,Resolution_Status,HashTag,Dept_ID,User_Name) VALUES('{$tweetdescription}','{$complaintlocation}', 'Open','{$hashtag}','{$deptid}','{$username}')";
mysql_query($insertQuery);
$settings = array('oauth_access_token' => "4064195836-Z0OPSodnw2ftFZZ70qiBVjtVnAcc7oy0AiIS7qb", 'oauth_access_token_secret' => "E7TXtTzaR9MqVxTobZxx09yxj55nXE5GnRfQvbUkSVqnl", 'consumer_key' => "YRF6qN2BML1reESGmDWilX3Yv", 'consumer_secret' => "GIZrEHTVpU5TefNqzg0wqznYgO0r1KCfNCIJidbFLGSKJsAJ20");
$desc = $tweetdescription . ' ' . $hashtag;
//$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
//url for getting list of followers
//$url = 'https://api.twitter.com/1.1/followers/list.json';
//$getfield = '?username=abhinay_balusu&skip_status=1';
//url for getting all the tweets related to a particular hashtag
//$url = 'https://api.twitter.com/1.1/search/tweets.json';
//$getfield = '?q=%23usopen&result_type=recent';
//url to pass location details to twitter api
//$url = 'https://api.twitter.com/1.1/geo/reverse_geocode.json';
//$getfield = '?lat=37.76893497&long=-122.42284884';
//url to pass location details along with the tweet to twitter api
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$requestMethod = 'POST';
$postfields = array('status' => $tweetdescription);
$twitter = new TwitterAPIExchange($settings);
$twitter->setPostfields($postfields)->buildOauth($url, $requestMethod)->performRequest();
if ($twitter) {
echo "Tweeted Successfully";
header("Location:user.php");
}