0

Hi I am trying to do the same thing. I would like to save the Facebook user timeline details OR messages in MySQL database. Timeline details are visible in screen total posts are like this http://screenshot.co/#!/2dcbee03ff , if I want to see the 'messages' only I can see in the screen like http://screenshot.co/#!/635a038dd5 but not able to store in database. I tried with the following Code snippet but I am not getting expected result. I am getting "Array" in the message field http://screenshot.co/#!/9385792e8a . Please help me how to store all messages in single row for single user.

$total_posts = array();
    $posts_response = $posts_request->getGraphEdge();
    if($fb->next($posts_response)) {
        $response_array = $posts_response->asArray();
        $total_posts = array_merge($total_posts, $response_array);
        while ($posts_response = $fb->next($posts_response)) {  
            $response_array = $posts_response->asArray();
            $total_posts = array_merge($total_posts, $response_array);  
        }
        //print_r($total_posts);
        foreach ($total_posts as $key ) {
            echo $key['message'].'<br>';
        }
    } else {
        $posts_response = $posts_request->getGraphEdge()->asArray();
        print_r($posts_response);
    }

// storing in the database.


    $sql = "INSERT INTO users1 (name, token, message) 
    VALUES ('{$name}', '{$accessToken}', '{$total_posts}')";
    if ($db->query($sql) === TRUE) {
    echo "New record created successfully !!";
    } else {
        echo "Error: " . $sql . "<br>" . $db->error;
    }
    $db->close();
4
Contributors
9
Replies
46
Views
1 Year
Discussion Span
Last Post by radow
0

turn your array into a string, make your column a blob. On the retrieve, you will have to unstringify your array.

The php methods you are looking for implode() and explode()

0

Hi, I did this is and screenshot of database is here http://screenshot.co/#!/e57ec7ccfb
and the code snippet is given below.

$total_posts = array();
    $posts_response = $posts_request->getGraphEdge();
    if($fb->next($posts_response)) {
        $response_array = $posts_response->asArray();
        $total_posts = array_merge($total_posts, $response_array);
        while ($posts_response = $fb->next($posts_response)) {  
            $response_array = $posts_response->asArray();
            $total_posts = array_merge($total_posts, $response_array);  
        }
        //print_r($total_posts);
        foreach ($total_posts as $key ) {
            echo $key['message'].'<br>';
        }
    } else {
        $posts_response = $posts_request->getGraphEdge()->asArray();
        print_r($posts_response);
    }

// storing in the database.
    $comma_separated = implode(",", $total_posts);

    $sql = "INSERT INTO users1 (name, token, message) 
    VALUES ('{$name}', '{$accessToken}', '{$comma_separated}')";
    if ($db->query($sql) === TRUE) {
    echo "New record created successfully !!";
    } else {
        echo "Error: " . $sql . "<br>" . $db->error;
    }
    $db->close();
0

So... solved? I don't think phpmyadmin shows blob text as text by default. You will need to figure out how to configure the query to show the blob as actual text.

0

yes , now I am trying to configure it how to convert blob as actual text. lets see.

0

Jeez! You want to actually store all this? When it's available from the FB API? What advantage does this give you? Sorry if I sound negative - just seems an odd thing to do - duplicating accessible data from elsewhere.

0

Some social media APIs (twitter) actually encourage this. Facebook is not one, however. But he may be data mining or using it for whatever reason..

0

It's the actual posts themselves that are being stored isn't it? I can understand taking aggregated data like total number of posts etc, but to actually store individual messages seems a bit much. Just wundrin' that's all.

0

actually I was trying to store timeline data for datamining. But not yet solved the matter yet. :(

0

Hi. You can to convert array to JSON and then its will save in databases.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.