Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kinlane/4445917dcdd28a1be958545f41e2caa3 to your computer and use it in GitHub Desktop.
Save kinlane/4445917dcdd28a1be958545f41e2caa3 to your computer and use it in GitHub Desktop.
parse-twitter-bookmarks-api-as-postman-collection-test.js
var jsonData = pm.response.json();
var tweets = '';
var all_links = [];
// list out all our links.
tweets = "<h2>Bookmarks</h2>";
tweets = tweets + '<ul>';
var tweet_results = jsonData.globalObjects.tweets;
// loop through all the favorited tweets from this respons
for (const [key, value] of Object.entries(tweet_results)) {
var text = value.full_text;
var url = value.entities.urls;
var id = key;
tweets = tweets + '<li>';
tweets = tweets + text + ' (tweet id:' + id + ')';
if(url.length > 0){
tweets = tweets + text + '<ul>';
for (var i = 0; i < url.length; i++){
var expanded_url = url[i].expanded_url;
tweets = tweets + '<li>' + expanded_url + '</li>';
}
tweets = tweets + '</ul>';
}
tweets = tweets + '</li>';
}
tweets = tweets + '</ul>';
pm.visualizer.set(tweets);
pm.environment.set("favorites",tweets);
@4chr4f
Copy link

4chr4f commented Jul 27, 2020

all works great just had to check url against undefined

var jsonData = pm.response.json();

var tweets = '';
var all_links = [];

// list out all our links.
tweets = "

Bookmarks

";
tweets = tweets + '
    ';

    var tweet_results = jsonData.globalObjects.tweets;

    // loop through all the favorited tweets from this respons
    for (const [key, value] of Object.entries(tweet_results)) {

    var text = value.full_text;
    var url = value.entities.urls;
    var id = key;
    
    tweets = tweets + '<li>';
    tweets = tweets + text  + ' (tweet id:' + id  + ')';
    
    if(undefined !== url && url.length > 0){
    
        tweets = tweets + text  + '<ul>';
        
        for (var i = 0; i < url.length; i++){
           var expanded_url = url[i].expanded_url;
           tweets = tweets + '<li>' + expanded_url  + '</li>';
        }
        
        tweets = tweets  + '</ul>';
    }
    
    tweets = tweets + '</li>';
    
    }
    

    tweets = tweets + '

';
pm.visualizer.set(tweets);
pm.environment.set("favorites",tweets);

@FireCode117
Copy link

FireCode117 commented Dec 31, 2020

Hello.

I get a different error when trying to run the script:

There was an error in evaluating the test script: JSONError: Unexpected token '<' at 1:1 ^

@postkin
Copy link

postkin commented Jan 4, 2021 via email

@cazvlad
Copy link

cazvlad commented Sep 24, 2021

@postkin

The GET API call you described in your article doesn't seem to exist anymore. When filtering for bookmark, these are the 3 results I get:
image

The first one pinged returns a crap mess of JS and no bookmarks.

The other two return 403 Forbidden.

Do you have any tips on navigating the situation?

Thank you so much for your support and documentation on this topic!

@kinlane
Copy link
Author

kinlane commented Sep 24, 2021

Sorry, my head hasn't been in here for a while -- don't have much to offer. Next time I pick up to play with I'll troubleshoot and provide some tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment