Here's my code:
$connection = new TwitterOAuth($consumer_key,$consumer_secret, $oAuthToken, $oAuthSecret);
// Get direct message data
$content = $connection ->get('https://api.twitter.com/1/direct_messages.json');
echo '<pre>',print_r($content,true),'</pre>';
function write_messages_to_database() {
require_once('connect_to_database');
$conn = mysql_connect("127.0.0.1", "Diego", "frafra") or die(mysql_error());
mysql_select_db('bot', $conn) or die(mysql_error());
foreach ($content as $directmessage) {
mysql_query("INSERT INTO 'twitter_senders' ('sender_id', 'sender_name'), VALUES ('{$content->id}', '{$content->sender_screen_name}')");
$directmessage_id = mysql_last_insert_id();
foreach ($directmessage->text as $text) {
mysql_query("INSERT INTO 'message_senders' ('message'), VALUES ('{$text->text}')");
}
}
}
Below, the array from which i just want to extract the values in id,sender_screen_name and text. Also, the array has three objects but i just pasted in one for the example.
I am not getting any error message, it's just the program is not writing into the database
What do you think?
Array
(
[0] => stdClass Object
(
[sender_id] => 374504554
[recipient_screen_name] => Infobot2012
[recipient_id] => 428575951
[recipient] => stdClass Object
(
[id] => 428575951
[profile_image_url] =>
[url] =>
[created_at] => Sun Dec 04 22:56:38 +0000 2011
[followers_count] => 3
[default_profile] => 1
[profile_background_color] => C0DEED
[lang] => en
[utc_offset] =>
[name] => Diego Canale
[profile_background_image_url] =>
[location] =>
[profile_link_color] => 0084B4
[listed_count] => 0
[verified] =>
[protected] =>
[profile_use_background_image] => 1
[is_translator] =>
[following] =>
[description] =>
[profile_text_color] => 333333
[statuses_count] => 10
[screen_name] => Infobot2012
[profile_image_url_https] =>
[time_zone] =>
[profile_background_image_url_https] =>
[friends_count] => 14
[default_profile_image] => 1
[contributors_enabled] =>
[profile_sidebar_border_color] => C0DEED
[id_str] => 428575951
[geo_enabled] =>
[favourites_count] => 0
[profile_background_tile] =>
[notifications] =>
[show_all_inline_media] =>
[profile_sidebar_fill_color] => DDEEF6
[follow_request_sent] =>
)
[id_str] => 194550124767227905
[sender] => stdClass Object
(
[id] => 374504554
[profile_image_url] =>
[url] =>
[created_at] => Fri Sep 16 12:46:20 +0000 2011
[followers_count] => 19
[default_profile] => 1
[profile_background_color] => C0DEED
[lang] => en
[utc_offset] =>
[name] => Diego Canale
[profile_background_image_url] =>
[location] => Dublin
[profile_link_color] => 0084B4
[listed_count] => 0
[verified] =>
[protected] =>
[profile_use_background_image] => 1
[is_translator] =>
[following] => 1
[description] =>
[profile_text_color] => 333333
[statuses_count] => 92
[screen_name] => sdiegolo
[profile_image_url_https] =>
[time_zone] =>
[profile_background_image_url_https] =>
[friends_count] => 79
[default_profile_image] =>
[contributors_enabled] =>
[profile_sidebar_border_color] => C0DEED
[id_str] => 374504554
[geo_enabled] =>
[favourites_count] => 1
[profile_background_tile] =>
[notifications] =>
[show_all_inline_media] =>
[profile_sidebar_fill_color] => DDEEF6
[follow_request_sent] =>
)
[created_at] => Mon Apr 23 22:15:38 +0000 2012
[id] => 1.9455012476723E+17
[sender_screen_name] => sdiegolo
[text] => Hello Infobot!
)
This post has been edited by Atli: 27 April 2012 - 03:34 PM
Reason for edit:: Added the second [code] tags. Far easier to read this way.

New Topic/Question
Reply



MultiQuote




|