How would one go about turning the contents of this JSON feed into Drupal nodes?
I have all modules in place. Got jsonpath-0.8.1.php where it belongs. Now I have no idea how to continue.

This is the type of json feed I'd like to import:
http://api.twitter.com/1/statuses/user_timeline.json?screen_name=drupal_...

Thanks for any support.

Comments

7wonders’s picture

For starters drop the &callback=jsonfeed from the end, I dont think its needed according to twitter as json is already being called with the user_timeline.json. It also gave me some errors at the online tool below.

http://dev.twitter.com/doc/get/statuses/user_timeline

Secondly, I highly recommended trying out this excellent tool:

http://jsonviewer.stack.hu/

Format option is great for cleaning up and viewer is brilliant for figuring out your paths.

So, first thing to do with drupal is create two new content types, one you can call "Twitter feed" and one you call "Twitter Item". Twitter feed can be left as is. Twitter Item you start adding fields to. For your example you will need fields like:

url
listed_count
description
statuses_count
favourites_count
profile_background_color
location
profile_background_image_url
profile_image_url

etc, etc. Depends on what you want to store. Keep in mind to try and pick the right field types (text, integer, link and so) but text is the easiest to work with for testing.

Once you have done that you go and set up a new feed importer. Im not going to go into all details but things to be sure to change are - attached to (needs to be set as the Twitter Feed item type), Parser (JSONPath Parser obviously), Node Processor -> settings -> content type (needs to be set to Twitter Item).

Next you go to Node Processor - > mapping. Here you choose Jsonpath expression as source and whichever of your new fields as targets. One target should be GUID and set to unique to avoid duplicates when importing.

When you have mapped to your fields (start with only a couple until you have figured it out) the fun begins :) Go and create new content of type Twitter Feed. Give it a title (Test) and in URL you add http://api.twitter.com/1/statuses/user_timeline.json?screen_name=drupal_...

click JSONPath Parser settings! Read this page - http://goessner.net/articles/JsonPath/

Context for yours will be (i think but havent tested) $..* This sets the base for everything else.

It looks like id_str is unique in this so use that as GUID by adding to the field guid id_str

Everything else you probably want is under user so for example all the items i listed above would be as follows:

user.url
user.listed_count
user.description
user.statuses_count
user.favourites_count
user.profile_background_color
user.location
user.profile_background_image_url
user.profile_image_url

Click debug and check all the boxes (to start so you can see any probs). Click save. Click Import on the newly created and node and everything will of course be fine and dandy!

Hope this helps someone. Great module by the way twistor! You should set up a documentation page where we can share our exported configs for various feeds :)

/7

7wonders’s picture

Im on drupal 7 by the way but assuming everything is similar.

twistor’s picture

Assigned: Unassigned » mitchell

Use for docs. Base them off xpathparser

mitchell’s picture

Version: 6.x-1.0-beta5 » 7.x-1.x-dev
Assigned: mitchell » Unassigned

>>You should set up a documentation page where we can share our exported configs for various feeds. :)
This reminds me of a quote, ~"If you see something wrong, don't just tell someone, fix it." Please see, #1093614: Create documentation handbook.

Chris, I won't be spending much more time building out project resources for the feeds related modules, but I'll try to keep up on the issue queues. I agree that Feeds XPath Parser is in good enough shape to say that Feeds' pluggable parsers' feature explanations exist and users/developers for each can continue from there. (*pressing un-volunteer button on jsonpath's project page, if it existed)

Are you still planning on merging the parser modules, which would make #1093614: Create documentation handbook a moot point? At drupalcon, fago said he would like to port your tamper plugins to actions, if that makes any difference in planning your projects. See #745314: Action: transform text.

Anonymous’s picture

Status: Active » Fixed

To answer the original question, how to import Twitter JSON (API 1.1.)?

Simply install this module. Create a feed importer as usual. Select the JSONPath Parser. Setup your mappings.

For a feed like this:
http://api.twitter.com/1/statuses/user_timeline.json?screen_name=drupal_...

The JSONPath context will be
$.*

Then, for example, the following mappings:

Title: text
GUID: id
Published date: created_at
Body: text

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

vince.rowe’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta2
Status: Closed (fixed) » Needs review

Hi there,

The comments and advise in this thread work perfectly for v1 of the Twitter API. That API version has now been retired and is no longer accepting requests.
This means there is still a need to use this module to parse a Twitter feed, but now authentication is required in the API v1.1 as noted in the Twitter page here:

https://dev.twitter.com/blog/api-v1-retirement-final-dates

I understand this module is not specifically for Twitter, so if this is out of scope thats understandable, I thought it was worth referencing it here just in case, and especially to help people following the above recommendations as they will no longer work.

Has anyone looked into this, or planning to?

Thanks

chrsnlsn’s picture

Wrestling with this today, the solution seems to be using this module to parse and using the Feeds OAuth for authentication. Got everything working again after a few hours of messing around.

twistor’s picture

Issue summary: View changes
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.