This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i_twitter.php
executable file
·82 lines (70 loc) · 2.21 KB
/
i_twitter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
if ( !defined('ABSPATH') ) {
/** Set up WordPress environment */
require_once( dirname( __FILE__ ) . '/../wp-load.php' );
}
ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "",
'oauth_access_token_secret' => "",
'consumer_key' => "",
'consumer_secret' => ""
);
/** URL for REST request, see: https://dev.twitter.com/docs/api/1.1/ **/
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=#rusesignal';
$requestMethod = 'GET';
/** Perform a POST request and echo the response **/
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$json_dec = json_decode($response);
foreach ($json_dec->statuses as $status)
{
$args = array(
//'post_type' => 'post',
'meta_query' => array(
array(
'key' => 'twitter_post_id',
'value' => $status->id_str,
),
),
);
$query = new WP_Query( $args );
//echo $query->request;
$post_exists=false;
if ($query->have_posts())
{
$post_exists=true;
}
if (array_key_exists('retweeted_status',$status))
{
$post_exists=true;
}
//check for whitelist,blacklist and graylist
echo "https://twitter.com/".$status->user->screen_name."/status/".$status->id_str."\r\n";
$twt_url = "https://twitter.com/".$status->user->screen_name."/status/".$status->id_str;
$datetime = new DateTime($status->created_at);
$datetime->modify("+3 hours");
$my_post = array(
'post_title' => 'Сигнал '.$datetime->format('Y-m-d') . ' ' . $datetime->format('H:i:s'),
'post_content' => $twt_url,
'post_status' => 'publish',
'post_author' => 1,
// 'post_date' => $datetime->format('Y-m-d') . ' ' . $datetime->format('H:i:s'),
'tags_input' => $status->user->screen_name,
'post_category' => array(3)
);
// Insert the post into the database
if ($post_exists==false)
{
$post_id = wp_insert_post( $my_post );
add_post_meta ($post_id, "source", "twitter");
add_post_meta ($post_id, "twitter_post_id", $status->id_str);
add_post_meta ($post_id, "twitter_user_id", $status->user->id_str);
}
}
?>