iTunes Search API: Update Notification

347 Views Asked by At

i'm using iTunes API Search and Advanced Custom Field WordPress plugin so the wp author can add a mac app id to a custom field and the implanted iTunes Search API above will add all the other information of app automatically in the wp post. and when app information updated my wp post will have the updated info like last verion number app size and ...

but the problem is my own wrote review and guide of any verion of any app inside my website and it need to be updated manually.

for example i have added a post for version 3.7.1 of "Things 3" mac app using method above to my WordPress and i have reviewed this version with my own description and hand-wrote in the post.

now i need to get notified when ever this app gets a new version or update so i can update my review and add some text for new version inside the post as well.

is there any way or method you guys can think of, so i can get notified when ever an app i have reviewed in my site gets an update ?

i really appreciate any way or taught !

Thanks.

2

There are 2 best solutions below

7
On

There is no native API to do what you're asking.

However, with a little coding I believe you could use the RSS feed of the application to then create something to notify you on a change.

See Example for the App HomeScan https://itunes.apple.com/lookup?id=1380025232

ID= YOURAPPID

I believe this should give you some general direction to do what you need.

0
On

This is a reply to our comment history in the other answer.

@erfanMHD, there are a number of ways to really do this. You don't have to do it in javascript. This isn't really something someone can give you an easy code snippet for since it requires a few additional things and is generally frowned upon in StackOverflow.

You'll need somewhere to store the localVersion of the application of the review you last wrote. In the example I wrote below I used a simple MySQL database to hold the local version. You'll also need to figure out how you want to display the data. I know you can add stuff to the wordpress dashboard but this isn't something we can show you how to do via StackOverflow.

However, below is a very simple (JUST FOR REFERENCE) purposes only on how one could achieve what you're trying to do. However this is just an example to guide you along the process.

For this demo, you'll need a MySQL database with a DBName of test and and a record created called application_version with 3 rows. ID, Name, Version.

<?php
    $servername = "localhost"; // Your MySQL Server
    $username = "root"; // Your MySQL Username
    $password = "password"; // Your MySQL Password
    $dbname = "test"; // The name of your MySQL database
    $id = "904280696"; // The ID of the applicaiton you're wanting to check

    function search($searchTerm){

        // Construct our API / web services lookup URL.
        $url = 'https://itunes.apple.com/lookup?id=' . urlencode($searchTerm);

        // Use file_get_contents to get the contents of the URL.
        $result = file_get_contents($url);

        // If results are returned.
        if($result !== false){
            // Decode the JSON result into an associative array and return.
            return json_decode($result, true);
        }

        // If we reach here, something went wrong.
        return false;

    }

    function updateVersion($id, $name, $version) {

        // Create MySQL connection
        $conn = new mysqli($GLOBALS['servername'], $GLOBALS['username'], $GLOBALS['password'], $GLOBALS['dbname']);

        // Check MySQL connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        }

        // Save the Version information
        $sql = "UPDATE application_version SET name='" . $name . "', version='" . $version . "' WHERE id='" . $id . "'";
        echo $sql;
        echo "<br>";

        // Run the Insert into MySQL
        if ($conn->query($sql) === TRUE) {

            // Print On Success
            echo "Record Updated Successfully";
            echo "<br>";
        } else {

            // We dun goofed
            echo "Error: " . $sql . "<br>" . $conn->error;
            echo "<br>";
        }

        $conn->close();
    }

    function getLocalVersion($id) {
        // Create MySQL connection
        $conn = new mysqli($GLOBALS['servername'], $GLOBALS['username'], $GLOBALS['password'], $GLOBALS['dbname']);

        // Check MySQL connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        }

        $sql = "SELECT * FROM application_version WHERE ID = " . $GLOBALS['id'];

        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
            echo "Found Application ID Entry in database";
            echo "<br>";
            echo "<table><tr><th>ID</th><th>Name</th><th>Version</th></tr>";

            // output data of each row
            while($row = $result->fetch_assoc()) {
                echo "<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["version"]."</td></tr>";
                $GLOBALS['storedVersion'] = $row["version"];
            }
            echo "</table>";
            echo "<br>";

        } else {
            echo "No Application ID Entry found in database";
            echo "<br>";
        }


        $conn->close();
    }

    // Search for your requested ID
    $searchResults = search($GLOBALS['id']);
    $currentVersion = '0.0.0';
    $storedVersion = '0.0.0';
    $appName = 'null';

    // Loop through the results.
    foreach($searchResults['results'] as $result){

        // Pass the current version to variable
        $currentVersion = $result['version'];
        $appName = $result['trackName'];

        // Get the current version or what ever else information you need
        echo 'Current Version: ' . $currentVersion;
        echo "<br>";
        echo "<br>";
    }

    // Get Local Version from database
    getLocalVersion($id);

    if ($currentVersion > $storedVersion) {
        echo "You have an old version friend";
        echo "<br>";

        // Write what you want it to do here

        updateVersion($id, $appName, $currentVersion);
    } else {
        echo "You're all up to date";
        echo "<br>";

        // Write what you don't want it to do here
    }
?>

Again, this is just quick and dirty. You'd want to do a lot of additional checks and balances. One I see right off the bat would be in the check for inserting.