meerdere rss feed in twitter api script zetten om automatische naar twitter te sturen
het gaat om deze vier rss feeds die in de twitter api moeten verwerkt worden.
Politie: https://alarmeringen.nl/feeds/region/haaglanden/politie.rss
Brandweer: https://alarmeringen.nl/feeds/region/haaglanden/brandweer.rss
Ambulance: https://alarmeringen.nl/feeds/region/haaglanden/ambulance.rss
Traumahelikopter: https://alarmeringen.nl/feeds/discipline/trauma.rss
Alvast dank die mij wil helpen
Sander van den Berg
Examples-twitter-php-api
Code (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
// Orginal Twiter API PHP https://github.com/pedroventura/pv-auto-tweets
// Twitter API PHP examples https://github.com/fxstar/auto-tweets-php-api
$consumerKey = 'Consumer-Key';
$consumerSecret = 'Consumer-Secret';
$oAuthToken = 'OAuthToken';
$oAuthSecret = 'OAuth Secret';
# API OAuth
require_once('twitteroauth.php');
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
// get followers id list last 5000
echo $tweet->get('followers/ids', array('screen_name' => 'YOUR-SCREEN-NAME-USER', 'count'=> 5000));
//$tweet->get('followers/ids', array('screen_name' => 'YOUR-SCREEN-NAME-USER', 'cursor' => 9999999999));
// get followers list with name last 200
echo $tweet->get('followers/list', array('screen_name' => 'YOUR-SCREEN-NAME-USER', 'count' => 200));
//$tweet->get('followers/list', array('screen_name' => 'YOUR-SCREEN-NAME-USER', 'cursor' => 9999999999));
// send message to followers last 200
$out="";
$t = json_decode($tweet->get('followers/list', array('screen_name' => 'YOUR-SCREEN-NAME-USER', 'count' => 200)), true);
foreach ($t['users'] as $user) {
$tweet->post('direct_messages/new', array('screen_name' => $user['screen_name'], 'text' => 'Hello!'));
$out = $out."Username ".$user['screen_name']." ID ".$user['id_str']."<br>";
}
// save to file
file_put_contents('followers.txt', $out);
// send private message
echo $tweet->post('direct_messages/new', array('screen_name' => 'SCREEN-NAME-USER', 'text' => 'Hell ha wrrrrrrr......'));
// New Tweet message
$tweetMessage = 'This is a tweet to my Twitter account via PHP @fxstareu. PHP API the best ...';
// Check for 140 characters
if(strlen($tweetMessage) <= 140)
{
echo $tweet->post('statuses/update', array('status' => $tweetMessage));
}
// Auto follow users
function auto_follow($toa)
{
$followers = $toa->get('followers/ids', array('cursor' => -1));
$friends = $toa->get('friends/ids', array('cursor' => -1));
$a = json_decode($followers, true);
$b = json_decode($friends, true);
foreach ($a['ids'] as $id) {
if (empty($b['ids']) or !in_array($id, $b['ids'])) {
echo $id." Following user <br>";
$ret = $toa->post('friendships/create', array('user_id' => $id));
}
}
}
// Follow yours followers
auto_follow($tweet);
// search users and follow
function searchAndFollow($tweet, $search = "fxstareu"){
$users = $tweet->get('users/search', array('q' => $search));
$a = json_decode($users, true);
foreach ($a as $key => $user) {
echo $user['screen_name']." Follow user <br>";
$ret = $tweet->post('friendships/create', array('user_id' => $user['id']));
}
//print_r($a);
}
// search and follow
searchAndFollow($tweet, "fxstareu");
// all followers to file with send private messages
// (request limit 180 per 15 min)
$out="";
$cursor = "-1";
$t = json_decode($tweet->get('followers/list', array('screen_name' => 'microsoft', 'count' => 200)), true);
if (isset($t['errors'])) {
echo "ERRORS !!!!! ";
print_r($t['errors']);
die();
}
$cursor = $t['next_cursor_str'];
while ($cursor != 0) {
foreach ($t['users'] as $user) {
//$tweet->post('direct_messages/new', array('screen_name' => $user['screen_name'], 'text' => 'Hello!'));
$out = $out.$user['screen_name']."<br>";
}
$out = $out."NEXTPART";
sleep(1);
$t = json_decode($tweet->get('followers/list', array('screen_name' => 'microsoft', 'cursor' => $cursor, 'count' => 200)),true);
$cursor = $t['next_cursor_str'];
}
echo $out;
// save to file
file_put_contents('users.txt', $out);
// Geo location town lat long
// search geo
function searchGeoLatLong($tweet, $lat = "37.7821120598956", $long = "-122.400612831116", $max = "500"){
$users = $tweet->get('geo/search', array('lat' => $lat, 'long' => $long, 'max_results' => $max));
$a = json_decode($users, true);
echo "<pre>";
print_r($a);
foreach ($a as $key => $user) {
//echo $user['screen_name']." Follow user <br>";
//$ret = $tweet->post('friendships/create', array('user_id' => $user['id']));
}
}
function searchGeoTown($tweet, $search = "NewYork", $max = "500"){
$users = $tweet->get('geo/search', array('query' => $search, 'max_results' => $max));
$a = json_decode($users, true);
echo "<pre>";
print_r($a);
foreach ($a as $key => $user) {
//echo $user['screen_name']." Follow user <br>";
//$ret = $tweet->post('friendships/create', array('user_id' => $user['id']));
}
}
// search and follow
searchGeoTown($tweet, "warszawa");
searchGeoLatLong($tweet, "37.7821120598956", "-122.400612831116");
?>
// Orginal Twiter API PHP https://github.com/pedroventura/pv-auto-tweets
// Twitter API PHP examples https://github.com/fxstar/auto-tweets-php-api
$consumerKey = 'Consumer-Key';
$consumerSecret = 'Consumer-Secret';
$oAuthToken = 'OAuthToken';
$oAuthSecret = 'OAuth Secret';
# API OAuth
require_once('twitteroauth.php');
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
// get followers id list last 5000
echo $tweet->get('followers/ids', array('screen_name' => 'YOUR-SCREEN-NAME-USER', 'count'=> 5000));
//$tweet->get('followers/ids', array('screen_name' => 'YOUR-SCREEN-NAME-USER', 'cursor' => 9999999999));
// get followers list with name last 200
echo $tweet->get('followers/list', array('screen_name' => 'YOUR-SCREEN-NAME-USER', 'count' => 200));
//$tweet->get('followers/list', array('screen_name' => 'YOUR-SCREEN-NAME-USER', 'cursor' => 9999999999));
// send message to followers last 200
$out="";
$t = json_decode($tweet->get('followers/list', array('screen_name' => 'YOUR-SCREEN-NAME-USER', 'count' => 200)), true);
foreach ($t['users'] as $user) {
$tweet->post('direct_messages/new', array('screen_name' => $user['screen_name'], 'text' => 'Hello!'));
$out = $out."Username ".$user['screen_name']." ID ".$user['id_str']."<br>";
}
// save to file
file_put_contents('followers.txt', $out);
// send private message
echo $tweet->post('direct_messages/new', array('screen_name' => 'SCREEN-NAME-USER', 'text' => 'Hell ha wrrrrrrr......'));
// New Tweet message
$tweetMessage = 'This is a tweet to my Twitter account via PHP @fxstareu. PHP API the best ...';
// Check for 140 characters
if(strlen($tweetMessage) <= 140)
{
echo $tweet->post('statuses/update', array('status' => $tweetMessage));
}
// Auto follow users
function auto_follow($toa)
{
$followers = $toa->get('followers/ids', array('cursor' => -1));
$friends = $toa->get('friends/ids', array('cursor' => -1));
$a = json_decode($followers, true);
$b = json_decode($friends, true);
foreach ($a['ids'] as $id) {
if (empty($b['ids']) or !in_array($id, $b['ids'])) {
echo $id." Following user <br>";
$ret = $toa->post('friendships/create', array('user_id' => $id));
}
}
}
// Follow yours followers
auto_follow($tweet);
// search users and follow
function searchAndFollow($tweet, $search = "fxstareu"){
$users = $tweet->get('users/search', array('q' => $search));
$a = json_decode($users, true);
foreach ($a as $key => $user) {
echo $user['screen_name']." Follow user <br>";
$ret = $tweet->post('friendships/create', array('user_id' => $user['id']));
}
//print_r($a);
}
// search and follow
searchAndFollow($tweet, "fxstareu");
// all followers to file with send private messages
// (request limit 180 per 15 min)
$out="";
$cursor = "-1";
$t = json_decode($tweet->get('followers/list', array('screen_name' => 'microsoft', 'count' => 200)), true);
if (isset($t['errors'])) {
echo "ERRORS !!!!! ";
print_r($t['errors']);
die();
}
$cursor = $t['next_cursor_str'];
while ($cursor != 0) {
foreach ($t['users'] as $user) {
//$tweet->post('direct_messages/new', array('screen_name' => $user['screen_name'], 'text' => 'Hello!'));
$out = $out.$user['screen_name']."<br>";
}
$out = $out."NEXTPART";
sleep(1);
$t = json_decode($tweet->get('followers/list', array('screen_name' => 'microsoft', 'cursor' => $cursor, 'count' => 200)),true);
$cursor = $t['next_cursor_str'];
}
echo $out;
// save to file
file_put_contents('users.txt', $out);
// Geo location town lat long
// search geo
function searchGeoLatLong($tweet, $lat = "37.7821120598956", $long = "-122.400612831116", $max = "500"){
$users = $tweet->get('geo/search', array('lat' => $lat, 'long' => $long, 'max_results' => $max));
$a = json_decode($users, true);
echo "<pre>";
print_r($a);
foreach ($a as $key => $user) {
//echo $user['screen_name']." Follow user <br>";
//$ret = $tweet->post('friendships/create', array('user_id' => $user['id']));
}
}
function searchGeoTown($tweet, $search = "NewYork", $max = "500"){
$users = $tweet->get('geo/search', array('query' => $search, 'max_results' => $max));
$a = json_decode($users, true);
echo "<pre>";
print_r($a);
foreach ($a as $key => $user) {
//echo $user['screen_name']." Follow user <br>";
//$ret = $tweet->post('friendships/create', array('user_id' => $user['id']));
}
}
// search and follow
searchGeoTown($tweet, "warszawa");
searchGeoLatLong($tweet, "37.7821120598956", "-122.400612831116");
?>
index
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$consumerKey = 'Consumer-Key';
$consumerSecret = 'Consumer-Secret';
$oAuthToken = 'OAuthToken';
$oAuthSecret = 'OAuth Secret';
# API OAuth
require_once('twitteroauth.php');
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
# your code to retrieve data goes here, you can fetch your data from a rss feed or database
$tweet->post('statuses/update', array('status' => 'here the content of your tweet, you can add hashtags or links'));
?>
$consumerKey = 'Consumer-Key';
$consumerSecret = 'Consumer-Secret';
$oAuthToken = 'OAuthToken';
$oAuthSecret = 'OAuth Secret';
# API OAuth
require_once('twitteroauth.php');
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
# your code to retrieve data goes here, you can fetch your data from a rss feed or database
$tweet->post('statuses/update', array('status' => 'here the content of your tweet, you can add hashtags or links'));
?>
** code weggeknipt voor overzichtelijkheid **
Gewijzigd op 07/03/2017 20:06:55 door - Ariën -
Anders zul je toch iets met een cronjob en PHP moeten doen.
Vergeet ook niet dat "nooit meer een keer omkijken" niet bestaat. Je zult zelf in de gaten moeten houden of de boel nog werkt. De RSSfeed kan bijv. een andere URL krijgen, of een site zoals IFTTT kan hun diensten aanpassen.
Ik zelf lees voor mijn site ook een hoop RSS-feeds uit, en ik log alle foutmeldingen in de database, soms wil er wel eens een feed (helaas) niet werken vanwege een nieuwe URL.
Gewijzigd op 07/03/2017 16:12:13 door - Ariën -
Dat heb ik al geprobeerd ifttt Ariën en dan duur een kwartier voor dat het verstuurd is en ik wil het graag direct naar twitter gestuurd hebben. Maar ik heb het api key script op mijn pc staan dus kan zo omgebouwd worden.
Ook heb ik de UBB-tags aangepast, omdat er geen punt in hoort. Zie ook de Veelgestelde vragen
De examples die je laat zien zijn niet relevant voor wat jij wilt. Het enige wat jij wilt staat al in je index-bestand die je toont. Die zorgt ervoor dat een tweet wordt geplaatst. Uiteraard moet je ook de RSS-feed uitlezen, in een database markeren als 'verwerkt' en per item in de feed deze in een tweet plaatsen, tenzij hij al eerder verwerkt is. Je wilt immers niks herhalen.
Houd er ook rekening mee dat P2000-berichten ergens in de komende jaren versleuteld gaan worden, en dat ze niet meer of zeer beperkt op internet gebruikt kunnen worden. Het is al een project wat al vele jaren speelt binnen de politiek , maar ik vrees dat dit binnen 3 á 4 jaar wel eens werkelijkheid kan gaan worden, en de doodsteek voor dergelijke sites gaat worden. Zie ook deze site.