Mengakses Informasi Cuaca Dari AccuWeather

From Indonesian Research And Development Center
Jump to: navigation, search

Disclaimer

Tutorial ini hanya untuk tujuan pembelajaran semata, penulis tidak bertanggungjawab atas penggunaan maupun penyalahgunaan informasi yang terdapat pada tutorial ini. This tutorial is for educational purpose ONLY! I'm not responsible for it's use or misuse. Use at your own risk.


Pendahuluan

Tutorial singkat kali ini akan membahas cara memperoleh informasi cuaca dari situs AccuWeather dengan melakukan proses reverse engineering sederhana terhadap aplikasi android yang menggunakan layanan dari AccuWeather.


Langkah-langkah

Pada bagian ini akan dibahas 2 buah aplikasi android yang menggunakan layanan dari AccuWeather. Berikut ini adalah penjelasan untuk masing-masing aplikasi tersebut. Kedua aplikasi tersebut sebenarnya berkaitan dengan teknologi MirrorLink yang telah digunakan pada beberapa jenis kendaraan bermotor dan fungsinya adalah untuk memudahkan pengguna kendaraan untuk mengakses aplikasi yang terdapat pada perangkat telepon seluler melalui perangkat hiburan (head unit) yang terdapat pada kendaraan.


Aplikasi Land Rover InControl™ Remote

  • Setelah proses mengunduh selesai, lanjutkan dengan membuka aplikasi tersebut menggunakan androguard, JD-GUI atau aplikasi lainnya yang dapat melakukan analisis terhadap aplikasi untuk sistem operasi android.
  • Perhatikan pada bagian package com.jlr.jaguar.api.b, tepatnya pada class b. Berikut ini adalah potongan kode sumber yang terdapat pada bagian tersebut:
package com.jlr.jaguar.api.b;

import android.location.Location;
import android.os.AsyncTask;
import com.jlr.jaguar.app.models.Operation;
import com.jlr.jaguar.app.models.Operation.Parameter;
import java.io.IOException;
import java.net.URI;
import java.util.Locale;
import java.util.concurrent.Executor;
import org.apache.http.HttpResponse;

public class b
  extends bf
{
  private static final String a = "https://api.accuweather.com/locations/v1/cities/geoposition/search.json?q=%f,%f&apikey=%s";

  protected void a()
  {
    Location localLocation = (Location)this.g.getParameter(Operation.Parameter.LOCATION);
    Locale localLocale = Locale.US;
    Object[] arrayOfObject = new Object[3];
    arrayOfObject[0] = Double.valueOf(localLocation.getLatitude());
    arrayOfObject[1] = Double.valueOf(localLocation.getLongitude());
    arrayOfObject[2] = "f6626fd45bad4b5d8de03f602c89239a";
    this.k = URI.create(String.format(localLocale, "https://api.accuweather.com/locations/v1/cities/geoposition/search.json?q=%f,%f&apikey=%s", arrayOfObject));
  }
...
  • Pada bagian tersebut, bisa terlihat adanya API_KEY yang digunakan untuk mengakses layanan AccuWeather. Berikut ini adalah contoh penggunaan API_KEY tersebut untuk mencari lokasi tertentu berdasarkan koordinat (pada contoh berikut lokasinya adalah Tannu Tuva):
% curl -s 'https://api.accuweather.com/locations/v1/cities/geoposition/search.json?q=51.6980,94.3900&apikey=f6626fd45bad4b5d8de03f602c89239a' | jq '.'
{
  "Version": 1,
  "Key": "291128",
  "Type": "City",
  "Rank": 41,
  "LocalizedName": "Kyzyl",
  "EnglishName": "Kyzyl",
  "PrimaryPostalCode": "",
  "Region": {
    "ID": "ASI",
    "LocalizedName": "Asia",
    "EnglishName": "Asia"
  },
  "Country": {
    "ID": "RU",
    "LocalizedName": "Russia",
    "EnglishName": "Russia"
  },
  "AdministrativeArea": {
    "ID": "TY",
    "LocalizedName": "Tyva",
    "EnglishName": "Tyva",
    "Level": 1,
    "LocalizedType": "Republic",
    "EnglishType": "Republic",
    "CountryID": "RU"
  },
  "TimeZone": {
    "Code": "KRAT",
    "Name": "Asia/Krasnoyarsk",
    "GmtOffset": 7,
    "IsDaylightSaving": false,
    "NextOffsetChange": null
  },
  "GeoPosition": {
    "Latitude": 51.707,
    "Longitude": 94.423,
    "Elevation": {
      "Metric": {
        "Value": 626,
        "Unit": "m",
        "UnitType": 5
      },
      "Imperial": {
        "Value": 2053,
        "Unit": "ft",
        "UnitType": 0
      }
    }
  },
  "IsAlias": false,
  "SupplementalAdminAreas": [
    {
      "Level": 2,
      "LocalizedName": "",
      "EnglishName": "Kyzyl City"
    }
  ]
}
  • Dari informasi di atas, bisa terlihat bahwa ID (Key) untuk kota Kyzyl adalah 291128. Selanjutnya, untuk memperoleh informasi cuaca pada kota tersebut, Anda dapat menggunakan cara seperti ini:
% curl -s 'https://api.accuweather.com/currentconditions/v1/291128.json?apikey=f6626fd45bad4b5d8de03f602c89239a' | jq '.'
[
  {
    "LocalObservationDateTime": "2016-02-20T14:10:00+07:00",
    "EpochTime": 1455952200,
    "WeatherText": "Mostly cloudy",
    "WeatherIcon": 6,
    "IsDayTime": true,
    "Temperature": {
      "Metric": {
        "Value": -11.3,
        "Unit": "C",
        "UnitType": 17
      },
      "Imperial": {
        "Value": 12,
        "Unit": "F",
        "UnitType": 18
      }
    },
    "MobileLink": "http://m.accuweather.com/en/ru/kyzyl/291128/current-weather/291128?lang=en-us",
    "Link": "http://www.accuweather.com/en/ru/kyzyl/291128/current-weather/291128?lang=en-us"
  }
]
  • Pada bagian selanjutnya, akan dibahas cara aplikasi Samsung DriveLink mengakses layanan AccuWeather.


Aplikasi Samsung DriveLink

  • Aplikasi samsung DriveLink sedikit berbeda dengan aplikasi Land Rover InControl™ Remote karena mengakses layanan AccuWeather menggunakan format XML. Pertama, unduh aplikasi Samsung DriveLink dari situs GooglePlay.
  • Selanjutnya, sama seperti bagian di atas, gunakan androguard, JD-GUI atau aplikasi lainnya untuk melakukan analisis terhadap aplikasi DriveLink tersebut.
  • Pada bagian package app.scm.a.a, tepatnya pada class c, terdapat potongan kode berikut ini:
class c
  extends AsyncTask
{
  private j a;

  protected l a(String... paramVarArgs)
  {
    l locall = new l();
    String str1 = paramVarArgs[0];
    String str2 = paramVarArgs[1];
    String str3 = paramVarArgs[2];
    String str4 = paramVarArgs[3];
    String str5 = str4 + "_" + str3;
    int i;
    String str6;
    Object localObject1;
    if (a.a().get(str5) != null)
    {
      i = ((Integer)a.a().get(str5)).intValue();
      Object[] arrayOfObject = new Object[3];
      arrayOfObject[0] = str1;
      arrayOfObject[1] = str2;
      arrayOfObject[2] = Integer.valueOf(i);
      str6 = String.format("http://samsungmobile.accu-weather.com/widget/samsungmobile/weather-data.asp?latitude=%1$s&longitude=%2$s&langid=%3$d", arrayOfObject);
      localObject1 = null;
    }
  • Anda dapat menggunakan parameter berupa koordinat bujur dan lintang untuk memperoleh informasi cuaca di lokasi tersebut. Berikut ini adalah contohnya:
% curl -s 'http://samsungmobile.accu-weather.com/widget/samsungmobile/weather-data.asp?latitude=51.6980&longitude=94.3900'
<?xml version="1.0"  encoding="utf-8"?>
    <adc_database xmlns="http://www.accuweather.com">
        <units>
            <temp>F</temp>
            <dist>MI</dist>
            <speed>MPH</speed>
            <pres>IN</pres>
            <prec>IN</prec>
        </units>
    <local>
    <city>Kyzyl</city>
    <state>Tyva</state>
    <lat>51.70672</lat>
    <lon>94.42333</lon>
    <time>14:24</time>
    <timeZone>7</timeZone>
    <obsDaylight>
    0
    </obsDaylight>
    <currentGmtOffset>7</currentGmtOffset>
    <timeZoneAbbreviation>KRAT</timeZoneAbbreviation>
    </local>
        <currentconditions>
                    <url>http://www.accuweather.com/m/en-us/RU/TY/Kyzyl/current.aspx?p=samsungmobile&cityId=291128</url>
            <observationtime>2:24 PM</observationtime>
            <pressure state="Steady">30.50</pressure>
            <temperature>12</temperature>
            <realfeel>8</realfeel>
            <humidity>45%</humidity>
            <weathertext>Mostly cloudy</weathertext>
            <weathericon>06</weathericon>
            <windgusts>5</windgusts>
            <windspeed>5</windspeed>
            <winddirection>SSW</winddirection>
            <visibility>7</visibility>
            <precip>0.00</precip>
            <uvindex index="1">Low</uvindex>
            <dewpoint>-6</dewpoint>
            <cloudcover>88%</cloudcover>
        </currentconditions>
<planets>
<sun rise="7:48 AM" set="6:05 PM"/>
<moon rise="2/20/2016 3:41:00 PM" set="2/21/2016 6:45:00 AM"/>
<mercury rise="12:07 AM" set="8:47 AM"/>
<venus rise="11:49 PM" set="8:26 AM"/>
<mars rise="6:40 PM" set="3:44 AM"/>
<jupiter rise="12:41 PM" set="1:42 AM"/>
<saturn rise="8:32 PM" set="4:51 AM"/>
<uranus rise="2:14 AM" set="3:28 PM"/>
<neptune rise="1:09 AM" set="11:48 AM"/>
<pluto rise="10:46 PM" set="7:06 AM"/>
</planets>
            <moon>
                    <phase date="2/20/2016" text="Waxing Gibbous" >11</phase>
                    <phase date="2/21/2016" text="Waxing Gibbous" >12</phase>
                    <phase date="2/22/2016" text="Full" >14</phase>
                    <phase date="2/23/2016" text="Full" >14</phase>
                    <phase date="2/24/2016" text="Waning Gibbous" >15</phase>
                    <phase date="2/25/2016" text="Waning Gibbous" >16</phase>
                    <phase date="2/26/2016" text="Waning Gibbous" >17</phase>
                    <phase date="2/27/2016" text="Waning Gibbous" >18</phase>
                    <phase date="2/28/2016" text="Waning Gibbous" >19</phase>
                    <phase date="2/29/2016" text="Waning Gibbous" >20</phase>
                    <phase date="3/1/2016" text="Last" >21</phase>
                    <phase date="3/2/2016" text="Last" >21</phase>
                    <phase date="3/3/2016" text="Waning Crescent" >22</phase>
                    <phase date="3/4/2016" text="Waning Crescent" >23</phase>
                    <phase date="3/5/2016" text="Waning Crescent" >24</phase>
                    <phase date="3/6/2016" text="Waning Crescent" >25</phase>
                    <phase date="3/7/2016" text="Waning Crescent" >26</phase>
                    <phase date="3/8/2016" text="New" >1</phase>
                    <phase date="3/9/2016" text="New" >1</phase>
                    <phase date="3/10/2016" text="New" >1</phase>
                    <phase date="3/11/2016" text="New" >1</phase>
                    <phase date="3/12/2016" text="Waxing Crescent" >2</phase>
                    <phase date="3/13/2016" text="Waxing Crescent" >3</phase>
                    <phase date="3/14/2016" text="Waxing Crescent" >4</phase>
                    <phase date="3/15/2016" text="First" >7</phase>
                    <phase date="3/16/2016" text="Waxing Crescent" >6</phase>
                    <phase date="3/17/2016" text="First" >7</phase>
                    <phase date="3/18/2016" text="Waxing Gibbous" >8</phase>
                    <phase date="3/19/2016" text="Waxing Gibbous" >9</phase>
                    <phase date="3/20/2016" text="Waxing Gibbous" >10</phase>
                    <phase date="3/21/2016" text="Waxing Gibbous" >11</phase>
                    <phase date="3/22/2016" text="Waxing Gibbous" >12</phase>
            </moon>
            <images>
                <url>http://www.accuweather.com/m/en-us/RU/TY/Kyzyl/radar.aspx?p=samsungmobile&cityId=291128</url>
                    <radar>
                        http://sirocco.accuweather.com/adc_sat_108x81_public/ir/isASIA.gif
                    </radar>
            </images>
            <mapSpace>
            <image resolution="480x480" url="http://vortex.accuweather.com/adc2004/mapspace/world_ir/480x480/ASIA.png"/>
            </mapSpace>
            <forecast>
                <url>http://www.accuweather.com/m/en-us/RU/TY/Kyzyl/forecast.aspx?p=samsungmobile&cityId=291128</url>
                    <day number="1">
                        <url>http://www.accuweather.com/m/en-us/RU/TY/Kyzyl/details1.aspx?p=samsungmobile&cityId=291128</url>
                    <obsdate>2/20/2016</obsdate>
                    <daycode>Saturday</daycode>
                        <sunrise>7:48 AM</sunrise>
                        <sunset>6:05 PM</sunset>
                    <daytime>
                        <txtshort>Morning flurries and squalls</txtshort>
                        <txtlong>A few flurries and a heavier squall this morning; cloudy with a flurry this afternoon</txtlong>
                        <weathericon>19</weathericon>
                        <hightemperature>12</hightemperature>
                        <lowtemperature>-4</lowtemperature>
                        <realfeelhigh>13</realfeelhigh>
                        <realfeellow>-4</realfeellow>
                        <windspeed>2</windspeed>
                        <winddirection>SSE</winddirection>
                        <windgust>5</windgust>
                        <maxuv>1</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.1</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.06</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>64</snowProbability>
                        <iceProbability>7</iceProbability>
                        <precipitationProbability>65</precipitationProbability>
                    </daytime>
                    <nighttime>
                        <txtshort>A flurry early; clearing</txtshort>
                        <txtlong>A stray evening flurry; otherwise, clearing</txtlong>
                        <weathericon>43</weathericon>
                        <hightemperature>12</hightemperature>
                        <lowtemperature>-4</lowtemperature>
                        <realfeelhigh>13</realfeelhigh>
                        <realfeellow>0</realfeellow>
                        <windspeed>3</windspeed>
                        <winddirection>NW</winddirection>
                        <windgust>5</windgust>
                        <maxuv>1</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.1</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.01</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>40</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>45</precipitationProbability>
                    </nighttime>
                    </day>
                    <day number="2">
                        <url>http://www.accuweather.com/m/en-us/RU/TY/Kyzyl/details2.aspx?p=samsungmobile&cityId=291128</url>
                    <obsdate>2/21/2016</obsdate>
                    <daycode>Sunday</daycode>
                        <sunrise>7:46 AM</sunrise>
                        <sunset>6:07 PM</sunset>
                    <daytime>
                        <txtshort>Brilliant sunshine</txtshort>
                        <txtlong>Brilliant sunshine</txtlong>
                        <weathericon>01</weathericon>
                        <hightemperature>15</hightemperature>
                        <lowtemperature>-17</lowtemperature>
                        <realfeelhigh>23</realfeelhigh>
                        <realfeellow>-2</realfeellow>
                        <windspeed>2</windspeed>
                        <winddirection>SW</winddirection>
                        <windgust>5</windgust>
                        <maxuv>2</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.0</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.00</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>17</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>17</precipitationProbability>
                    </daytime>
                    <nighttime>
                        <txtshort>Clear</txtshort>
                        <txtlong>Clear</txtlong>
                        <weathericon>33</weathericon>
                        <hightemperature>15</hightemperature>
                        <lowtemperature>-17</lowtemperature>
                        <realfeelhigh>10</realfeelhigh>
                        <realfeellow>-11</realfeellow>
                        <windspeed>1</windspeed>
                        <winddirection>E</winddirection>
                        <windgust>3</windgust>
                        <maxuv>2</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.0</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.00</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>6</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>6</precipitationProbability>
                    </nighttime>
                    </day>
                    <day number="3">
                        <url>http://www.accuweather.com/m/en-us/RU/TY/Kyzyl/details3.aspx?p=samsungmobile&cityId=291128</url>
                    <obsdate>2/22/2016</obsdate>
                    <daycode>Monday</daycode>
                        <sunrise>7:44 AM</sunrise>
                        <sunset>6:09 PM</sunset>
                    <daytime>
                        <txtshort>Sunny</txtshort>
                        <txtlong>Sunny</txtlong>
                        <weathericon>01</weathericon>
                        <hightemperature>11</hightemperature>
                        <lowtemperature>-17</lowtemperature>
                        <realfeelhigh>19</realfeelhigh>
                        <realfeellow>-12</realfeellow>
                        <windspeed>1</windspeed>
                        <winddirection>SSE</winddirection>
                        <windgust>2</windgust>
                        <maxuv>2</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.0</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.00</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>13</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>13</precipitationProbability>
                    </daytime>
                    <nighttime>
                        <txtshort>Clear</txtshort>
                        <txtlong>Clear</txtlong>
                        <weathericon>33</weathericon>
                        <hightemperature>11</hightemperature>
                        <lowtemperature>-17</lowtemperature>
                        <realfeelhigh>8</realfeelhigh>
                        <realfeellow>-10</realfeellow>
                        <windspeed>1</windspeed>
                        <winddirection>ESE</winddirection>
                        <windgust>2</windgust>
                        <maxuv>2</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.0</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.00</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>7</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>7</precipitationProbability>
                    </nighttime>
                    </day>
                    <day number="4">
                        <url>http://www.accuweather.com/m/en-us/RU/TY/Kyzyl/details4.aspx?p=samsungmobile&cityId=291128</url>
                    <obsdate>2/23/2016</obsdate>
                    <daycode>Tuesday</daycode>
                        <sunrise>7:42 AM</sunrise>
                        <sunset>6:11 PM</sunset>
                    <daytime>
                        <txtshort>Partial sunshine</txtshort>
                        <txtlong>Partial sunshine</txtlong>
                        <weathericon>03</weathericon>
                        <hightemperature>12</hightemperature>
                        <lowtemperature>-3</lowtemperature>
                        <realfeelhigh>16</realfeelhigh>
                        <realfeellow>-11</realfeellow>
                        <windspeed>2</windspeed>
                        <winddirection>NE</winddirection>
                        <windgust>3</windgust>
                        <maxuv>2</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.0</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.00</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>7</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>7</precipitationProbability>
                    </daytime>
                    <nighttime>
                        <txtshort>Plenty of clouds</txtshort>
                        <txtlong>Plenty of clouds</txtlong>
                        <weathericon>07</weathericon>
                        <hightemperature>12</hightemperature>
                        <lowtemperature>-3</lowtemperature>
                        <realfeelhigh>7</realfeelhigh>
                        <realfeellow>2</realfeellow>
                        <windspeed>2</windspeed>
                        <winddirection>E</winddirection>
                        <windgust>3</windgust>
                        <maxuv>2</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.0</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.00</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>24</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>25</precipitationProbability>
                    </nighttime>
                    </day>
                    <day number="5">
                        <url>http://www.accuweather.com/m/en-us/RU/TY/Kyzyl/details5.aspx?p=samsungmobile&cityId=291128</url>
                    <obsdate>2/24/2016</obsdate>
                    <daycode>Wednesday</daycode>
                        <sunrise>7:40 AM</sunrise>
                        <sunset>6:13 PM</sunset>
                    <daytime>
                        <txtshort>Cloudy</txtshort>
                        <txtlong>Cloudy</txtlong>
                        <weathericon>07</weathericon>
                        <hightemperature>19</hightemperature>
                        <lowtemperature>-3</lowtemperature>
                        <realfeelhigh>23</realfeelhigh>
                        <realfeellow>6</realfeellow>
                        <windspeed>1</windspeed>
                        <winddirection>SE</winddirection>
                        <windgust>3</windgust>
                        <maxuv>1</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.0</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.00</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>25</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>25</precipitationProbability>
                    </daytime>
                    <nighttime>
                        <txtshort>Considerable clouds</txtshort>
                        <txtlong>Considerable clouds</txtlong>
                        <weathericon>07</weathericon>
                        <hightemperature>19</hightemperature>
                        <lowtemperature>-3</lowtemperature>
                        <realfeelhigh>17</realfeelhigh>
                        <realfeellow>4</realfeellow>
                        <windspeed>1</windspeed>
                        <winddirection>E</winddirection>
                        <windgust>2</windgust>
                        <maxuv>1</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.0</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.00</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>25</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>25</precipitationProbability>
                    </nighttime>
                    </day>
                    <day number="6">
                        <url>http://www.accuweather.com/m/en-us/RU/TY/Kyzyl/details6.aspx?p=samsungmobile&cityId=291128</url>
                    <obsdate>2/25/2016</obsdate>
                    <daycode>Thursday</daycode>
                        <sunrise>7:38 AM</sunrise>
                        <sunset>6:14 PM</sunset>
                    <daytime>
                        <txtshort>Mostly sunny</txtshort>
                        <txtlong>Mostly sunny</txtlong>
                        <weathericon>02</weathericon>
                        <hightemperature>23</hightemperature>
                        <lowtemperature>-14</lowtemperature>
                        <realfeelhigh>29</realfeelhigh>
                        <realfeellow>4</realfeellow>
                        <windspeed>2</windspeed>
                        <winddirection>ESE</winddirection>
                        <windgust>4</windgust>
                        <maxuv>2</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.0</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.00</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>1</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>1</precipitationProbability>
                    </daytime>
                    <nighttime>
                        <txtshort>Clear</txtshort>
                        <txtlong>Clear</txtlong>
                        <weathericon>33</weathericon>
                        <hightemperature>23</hightemperature>
                        <lowtemperature>-14</lowtemperature>
                        <realfeelhigh>13</realfeelhigh>
                        <realfeellow>-2</realfeellow>
                        <windspeed>1</windspeed>
                        <winddirection>E</winddirection>
                        <windgust>4</windgust>
                        <maxuv>2</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.0</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.00</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>0</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>0</precipitationProbability>
                    </nighttime>
                    </day>
                    <day number="7">
                        <url>http://www.accuweather.com/m/en-us/RU/TY/Kyzyl/details7.aspx?p=samsungmobile&cityId=291128</url>
                    <obsdate>2/26/2016</obsdate>
                    <daycode>Friday</daycode>
                        <sunrise>7:36 AM</sunrise>
                        <sunset>6:16 PM</sunset>
                    <daytime>
                        <txtshort>Considerable cloudiness</txtshort>
                        <txtlong>Considerable cloudiness</txtlong>
                        <weathericon>07</weathericon>
                        <hightemperature>24</hightemperature>
                        <lowtemperature>2</lowtemperature>
                        <realfeelhigh>29</realfeelhigh>
                        <realfeellow>3</realfeellow>
                        <windspeed>2</windspeed>
                        <winddirection>ENE</winddirection>
                        <windgust>5</windgust>
                        <maxuv>2</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.0</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.00</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>24</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>25</precipitationProbability>
                    </daytime>
                    <nighttime>
                        <txtshort>Cloudy most of the time</txtshort>
                        <txtlong>Cloudy most of the time</txtlong>
                        <weathericon>38</weathericon>
                        <hightemperature>24</hightemperature>
                        <lowtemperature>2</lowtemperature>
                        <realfeelhigh>19</realfeelhigh>
                        <realfeellow>7</realfeellow>
                        <windspeed>2</windspeed>
                        <winddirection>NE</winddirection>
                        <windgust>4</windgust>
                        <maxuv>2</maxuv>
                        <rainamount>0.00</rainamount>
                        <snowamount>0.0</snowamount>
                        <iceamount>0.00</iceamount>
                        <precipamount>0.00</precipamount>
                        <tstormprob>0</tstormprob>
                        <rainProbability>0</rainProbability>
                        <snowProbability>24</snowProbability>
                        <iceProbability>0</iceProbability>
                        <precipitationProbability>25</precipitationProbability>
                    </nighttime>
                    </day>
            </forecast>
        <copyright>Copyright 2016 AccuWeather.com</copyright>
        <use>This document is intended only for use by authorized licensees of AccuWeather.com. Unauthorized use is prohibited. All Rights Reserved.</use>
        <product>samsung mobile</product>
        <redistribution>Redistribution Prohibited.</redistribution>
    </adc_database>
  • Bisa terlihat bahwa informasi yang diberikan sangat lengkap dengan cukup mengirimkan satu kali permintaan ke layanan AccuWeather. Hal yang menarik dari aplikasi Samsung DriveLink ini, adalah adanya informasi OAuth sebuah akun twitter yang kemungkinan digunakan untuk pengujian oleh pengembang aplikasi tersebut. Informasi tersebut dapat dilihat pada package app.scm.common.api.sns, dan berikut ini adalah potongan kode tersebut:
...
public void b()
{
this.m = c.a((Activity)a, "959429461-zCNyWiiWbS2zimPVamDZl2qb8pcOG1iSzifIiNHU");
this.n = c.a((Activity)a, "z2irOXEW9Alch6v4BVWnkxVjQp5Xv6N7HHLtBm5co");
}

public Twitter c()
{
ConfigurationBuilder localConfigurationBuilder = new ConfigurationBuilder();
if (this.l == null) {
  b();
}
for (;;)
{
  localConfigurationBuilder.setOAuthAccessToken(this.m);
  localConfigurationBuilder.setOAuthAccessTokenSecret(this.n);
  localConfigurationBuilder.setOAuthConsumerKey("myMl6EzvmMSkM2kmAs0A");
  localConfigurationBuilder.setOAuthConsumerSecret("pu9Rho2Hzipdiygveaxm7XLUqMw0F0l7LaFp0MRGXA");
  Configuration localConfiguration = localConfigurationBuilder.build();
  try
  {
    new OAuthAuthorization(localConfiguration);
    return new TwitterFactory(localConfiguration).getInstance();
  }
  catch (Exception localException) {}
  this.m = this.l.getToken();
  this.n = this.l.getTokenSecret();
}
return null;
}
...
  • Untuk mengetahui akun twitter yang terhubung dengan informasi OAuth tersebut, kita dapat membuat skrip python sederhana dengan memanfaatkan modul tweepy. Berikut ini adalah kode sumber yang dapat digunakan untuk memperoleh informasi akun tersebut:
#!/bin/env python
import tweepy

consumer_key = 'myMl6EzvmMSkM2kmAs0A'
consumer_secret = 'pu9Rho2Hzipdiygveaxm7XLUqMw0F0l7LaFp0MRGXA'
access_token = '959429461-zCNyWiiWbS2zimPVamDZl2qb8pcOG1iSzifIiNHU'
access_token_secret = 'z2irOXEW9Alch6v4BVWnkxVjQp5Xv6N7HHLtBm5co'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

print 'screen name: ' + tweepy.API(auth).me().screen_name
  • Simpan potongan kode di atas dengan nama samsung-drivelink.py, lalu jalankan dengan terlebih dahulu mengatur skrip tersebut sebagai executable atau menjalankannya seperti ini:
% ./samsung-drivelink.py
screen name: drivelink1
  • Dari hasil di atas, bisa terlihat bahwa akun yang terhubung dengan OAuth tersebut adalah drivelink1.


Penutup

Sekian tutorial singkat kali ini, semoga bermanfaat. Terima kasih kepada Tuhan Yang Maha Esa, Maxindo, N3 dan Anda yang telah membaca tutorial ini.


Referensi