need a sample php code

I have API key of https://www.trafiklab.se/api/sl-reseplanerare-31
Now I need sample php code to get traffic and way points with this api. Please provide me a sample php code to use this api by curl or by any another method.
shiv babbar Rapportera olämpligt innehåll

Kommentarer

  • shiv babbar
  • Hi Shiv,

    We don't have complete examples, but we are currently working on an open-source SDK. The documentation is a bit lacking at the moment as it is still being worked on, but it might be useful to you: https://github.com/trafiklab/sl-php-sdk

    The package can be installed using "composer require trafiklab/sl-php-sdk".

    An example on how this is used can be found in our Google Assistant demo project: https://github.com/trafiklab/google-assistant-demo/blob/master/app/Http/Controllers/RoutePlanningController.php

    These projects are available under the MPL-2 license. The exact terms can be found here: https://www.mozilla.org/en-US/MPL/2.0/

    Please note that our SDKs don't offer all the functionality of the APIs, only basic features are exposed. If you need features that are not implemented in the SDK, you can either fork our SDK and develop it further, or you can use the API as an example and write your own code based on it.

    Feel free to reach out if you have further questions.

    Greetings,
    Bert
    Team Trafiklab
  • Thank you Sir.
    shiv babbar
  • In the trip api https://api.sl.se/api2/TravelplannerV3_1/trip.<FORMAT>?key=<DIN API KEY> & parameters
    which parameter (keys) is belong to number of trains and buses in one Leg. Please see attached screenshot.

    shiv babbar
  • Hi Shiv,

    Every leg contains "product" details, for example:

    "Product": {
    "name": "TUNNELBANA 13",
    "num": "20678",
    "line": "13",
    "catOut": "METRO ",
    "catIn": "MET",
    "catCode": "1",
    "catOutS": "MET",
    "catOutL": "TUNNELBANA ",
    "operatorCode": "SL",
    "operator": "Storstockholms Lokaltrafik",
    "admin": "106013"
    },

    Using this information, you can get a list of all vehicles and vehicle types used in a trip. To be clear, example you pointed at in your screenshot is not how much busses are used, but for example metro line 11, tram line 21, boat 1473, ... which can all be found in the product data.

    Regards,
    Bert
    Team Trafiklab
  • Thank you Sir, It helped me.
    Sir, I want to ask one more question that is
    How can I determine the color of Bus and color of subway.
    Which is the key in api to find the color of the bus and subway.

    shiv babbar
  • You can retrieve this information using the SL lines and stops API. Example data from the response:

    {
    "LineNumber": "19",
    "LineDesignation": "19",
    "DefaultTransportMode": "tunnelbanans gröna linje",
    "DefaultTransportModeCode": "METRO",
    "LastModifiedUtcDateTime": "2007-08-24 00:00:00.000",
    "ExistsFromDate": "2007-08-24 00:00:00.000"
    },
    {
    "LineNumber": "19",
    "LineDesignation": "19",
    "DefaultTransportMode": "Waxholmsbolagets",
    "DefaultTransportModeCode": "SHIP",
    "LastModifiedUtcDateTime": "2009-09-02 00:00:00.000",
    "ExistsFromDate": "2009-09-02 00:00:00.000"
    },
    {
    "LineNumber": "199",
    "LineDesignation": "199",
    "DefaultTransportMode": "",
    "DefaultTransportModeCode": "BUS",
    "LastModifiedUtcDateTime": "2007-08-24 00:00:00.000",
    "ExistsFromDate": "2007-08-24 00:00:00.000"
    },
    {
    "LineNumber": "2",
    "LineDesignation": "2",
    "DefaultTransportMode": "blåbuss",
    "DefaultTransportModeCode": "BUS",
    "LastModifiedUtcDateTime": "2007-08-24 00:00:00.000",
    "ExistsFromDate": "2007-08-24 00:00:00.000"
    },
    {
    "LineNumber": "22",
    "LineDesignation": "22",
    "DefaultTransportMode": "Tvärbanan",
    "DefaultTransportModeCode": "TRAM",
    "LastModifiedUtcDateTime": "2007-08-24 00:00:00.000",
    "ExistsFromDate": "2007-08-24 00:00:00.000"
    },

    Red busses have no special naming, blue busses are indicated by blåbuss. The metro lines are linked to their line color/line name, and trams are linked to the name of their line as well. I hope this solves your question.

    Regards,
    Bert


    Team Trafiklab
  • Thank you Sir for your reply. But Sorry Sir, it didn't helped me, Because from above api url https://api.sl.se/api2/LineData.json?model=[model]&key=[key]

    I am getting nothing. It is showing error, {"StatusCode":1002,"Message":"Key is invalid"}

    How can I get colors from array ?
    I am using following url
    https://api.sl.se/api2/TravelplannerV3_1/trip.json?key=<DIN API KEY> & parameters.

    Please help me to get colors of the vehicles.
    shiv babbar
  • The status message {"StatusCode":1002,"Message":"Key is invalid"}  means that you are using a wrong API key. It is a different API, and therefore you need to use a different API key. You can create the API key by going to your project on Traifklab.se, edit your project and add the API, then retrieve the key for the added API.

    Regards,
    Bert
    Team Trafiklab

Kommentera eller skriv ett nytt inlägg

Ditt namn och inlägg kan ses av alla. Din e-post visas aldrig publikt.