Category: API

APIs such as Instagram, Open Streetmap and more

  • Adobe Animate and the OpenWeatherMap API

    Adobe Animate and the OpenWeatherMap API

    Part One: Adobe Animate and API

    Do you want to fetch data from an API and use the data in your Adobe Animate CC creative work? Animate CC productions are made by JavaScript and HTML canvas. In theory getting data should work.

    Let’s try!

    OpenWeatherMap

    The data from OpenWeatherMap is only available when you have a token. The first step is to create a user profile, and then to create a token. Then you can create the URL to fetch the weathere data.

    Above you see the API call. That’s the information we need in order to get data from the website. The data will be returned as JSON, but we can fetch the content and display it in Adobe Animate. You can create the string along these lines:

    var weather = 'https://api.openweathermap.org/data/2.5/weather?q=YOUR-CITY-HERE&appid=ADD-YOUR-TOKEN-HERE';

    The url will fetch data from the API in the form of JSON. The URL for the weather data is formed in the variable weather.

    A JSON object from OpenWeatherMap.

    The fetch() function will use the variable above, and that’s how we get the data for the JavaScript into the document:

    fetch( weather ).then( ... etc ... );

    Dynamic Texts

    Now we have the data. Then we want to use the data in the design. Here we will work with Dynamic Text Fields.

    Dynamic Text Field.
    Here the Dynamic Text Field is selected. In Propterties to the left it is named theCity. Now we can change the content dynamicly with JavaScript.

    On the stage you see two Dynamic Textfields called theDescription and theCity. If you want to change the text of these fields you could do it like this:

    _this.theCity.text = “Hello World”;

    But we need the text from the API. If you check out the content of the weather data in the console, you can see, that the name of the city is:

    data.name

    The city name is added to the Dynamic Text Fiels like this:

    _this.theCity.text = data.name;

    If you use the Inspect Tool in the browsesr you will be able to create Dynamic text fields for all the data in the object from OpenWeatherMap.

    The JavaScript

    In the actions layer you can add your Vanilla Javascript. Here is the script I used:

    /**
     * OpenWeatherMap API Demo
     * IMPORTANT
     * Don't use the code beautifier. It will ruin the => in the Js.
     **/
    
    // get this as a global var
    var _this = this;
    
    // Openweather API string
    var weather = 'https://api.openweathermap.org/data/2.5/weather?q=Aarhus&appid=ADD-YOUR-TOKEN-HERE';
    
    // get the weather data via query URI
    fetch(weather).then( response=>{
    	
    	return response.json();
    
    }).then(data => {
    
    	// JSON data to the console for inspection
    	console.log(data);
    
    	// add the weadther description,texts or images to theDescription
    	_this.theDescription.text = data.weather[0].description;
    	_this.theCity.text = data.name;
    
    }).
    catch (err => {
    	// Do something for an error here
    	console.log('There was an error.');
    });

    Now you can test the production. Use the inspection tool in order to use the data from the JSON object in Dynamic Text Fields.

    So that’s what it takes if you want to create an Adobe Animate production that can display data from OpenWeatherMap’s API. Of course you can work in a similar manner with other API’s and JSON objects.

    Display the Weather Forecast in WordPress

    In order to show your work in WordPress, you can use an iframe. Upload your production to a folder on your server. Then add am iframe along these lines:

    <iframe src="https://yoursite.net/yourFolder/weather.html" height="480" frameborder="0" style="overflow=hidden;"></iframe>

    When you upload your work you’ll need the HTML, JavaScript file and the images/ folder – of course with the images in the folder. You don’t need the .fla file, since it’s for production only, but I would recommend to put it there anyway. If you want to change anything, you’ll know where it is.

    Resources

  • Mapbox Cartogram

    It’s a quick start method for Mapbox. Upload a picture, and select the colors on your map from the picture.

    Mapbox Cartogram
    Mapbox Cartogram
  • Open Streetmap API (embed)



    View Larger Map

    Here Open Street Maps is embedded via a simple i-frame – but it’s just a standard map. Not much Leaflet or Mapbox styling is possible when we use the OSM embed options. But at least you may add a marker via the OSM web page. As far as I can see the marker is made via Leaflet somehow.

    Since the AUH is a behemoth building complex. But you can use the pointer in order to pinpoint an entrance or building.

  • API – what’s out there?

    The http://www.programmableweb.com/ is s vast collection of APIs for web developers. It is a fine place to start if you need some API service for your website or app.

  • APIs – more or less open data

    APIgee - adgang til mange APIer
    APIgee – adgang til mange APIer

    The Instagram API is just one among many APIs. Here is a list of interesting sites:

    These are just a few examples ….

    Developers can access the APIs for e.g. Instagram, Twitter, Facebook, Flickr etc. ( often a developer key, token or client_id is requiered ).

    A great portal to many APIs is APIgee – the interface is used by Instagram and many other providers of third part data.

    • Get Instagram image feeds – see my example on Instagram.
    • Method: find out how to format the URL, that will give you the wanted data.
    • As soon as your API sends a satisfying response, you can use the json parser.
    • The analysis of the json object will give you an idea of how to format strings for the AJAX script, such as:
      • data.data.link.url ( etc. )

    APIgee

    Via Instagram you can open APIgee. In the top left corner there is a drop down menu with access to many APIs. Choose one. Next to the name you’ll find a drop down menu for authentiation. Choose it. If you can work without authentiation so much the better. If not … well try to authentiate with your personal or professional user profile.

    The authentiation will give you a token. Add the token to the search string. Then you’re ready to format your jsonp searchstring urls, like this one:

    https://api.instagram.com/v1/users/261168726/followed-by?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    Workshop

    In groups choose an API from a json data provider. Experiment with the API, try to get interesting results – and when you have the data you want – style it with all the arts and tricks you know from CSS and jQuery.

    After lunch present your work in plenum.

    Upload your work as a group.

     

     

     

Enable Notifications OK No thanks

We use cookies - more information

Multimusen.dk will set a few cookies from Doubleclick, Google and the Social Media plugins they ay set some cookies. Some of my pages use APIs - such as YouTube, LinkedIn, Google Fonts, Google Maps, Mapbox, Spotify, Jetpack, Twitter, Facebook &c.. Such plugins may set the odd cookie.

Close