beaulebens / keyring-social-importers

A collection of importers which pull your content back from social networks, and into your own WordPress install.
32 stars 17 forks source link

Can an importer make its own HTTP requests for more data? #13

Closed ncot-tech closed 7 years ago

ncot-tech commented 7 years ago

I'm trying to modify the Facebook Importer found elsewhere on Github to work a bit nicer (but this isn't about the Facebook importer specifically...)

Facebook's API is quite complex in that you can say "give me all my posts" and it'll give just the text and the ID of that post in nicely formatted JSON. To get any more information about each post (attached images, links, people you've mentioned, thumbnails of linked sites, etc), you make further HTTP requests to Facebook, giving it the post ID you're interested in and the data you want.

So the routine would go something like this

  1. Build the URL like normal to get a list of posts
  2. Go through the returned list of posts, one at a time
  3. For each returned post, get its post ID
  4. Make a new request to Facebook for the actual content of that post
  5. Use that returned data to create a Wordpress post
  6. Repeat steps 3-5 for each post obtained in step 2

Is there a way to do step 4 from within the importer, or will I need to do something else? I can't see any mechanism from within the importer to do any actual HTTP requests... I'm guessing that's done elsewhere?

beaulebens commented 7 years ago

Yep, there's no reason why you couldn't do that. In step 4, you'd just want to make sure that you're using Keyring's request() method so that you're getting the authentication handled etc. You can use that via $this->service->request() within an importer.

Just be aware that making a lot of external requests will slow things down, and eventually potentially max out the memory available on your server.