Question

I'm new with php and with the Facebook application framework. This is my problem: I have a php application that gets some profile information from a Facebook user and from each of his friends. All these infos are in json format (retrieved by the url "graph.facebook.com + some fields + access token"). So I've got a certain number of URLs (json files) equal to the number of user's friends and I must upload these json files to my server (a free one). The pseudo-code that I use to achieve this:

  • build graph.facebook.com URL with necessary fields and access token (https://graph.facebook.com/USER-ID?fields=field1,...,fieldN&access_token=ACCESS-TOKEN)
  • then, for each url, I use: file_put_contents($filename, file_get_contents($url))

Last point is the problematic one. Since the token has a one-hour validity lifetime, I don't have much time to complete all the operations, and using file_put_contents($filename, file_get_contents($url)) it's very time expensive.

For example: for a user with about 400 friends the application takes 40 minutes (more or less).

The fields are these: first_name,last_name,id,education,birthday,political,gender,hometown,relationshi‌p_status,religion,location,locations,work,interested_in,inspirational_people,spor‌​ts,likes

Do you have any ideas to solve this problem?

Thank you all!

Was it helpful?

Solution

I have tried this way and it is faster: instead of using the operations described in the above post, i have used:

  • the facebook api: $facebook->api(with the necessary fields)
  • then with json_encode and file_put_contents i convert the array returned by the apui and put it on the server

the question is: why this way is a faster one?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top