Once you have a feed that's syntactically valid (even if it doesn't contain any data), you’re ready to set up the method you’ll use to provide your data to Google.
You can deliver realtime transit data 2 ways:
- Fetch, which allows Google to retrieve your data from a web-location
- Push, which allows you to upload your data via HTTP POST
If you can't provide service alerts via fetch or push methods, you can manually enter service alerts via the Service Alerts Editor in your Transit partner dashboard.
Fetch
You can host each of your realtime feeds at their own web-location. Google pulls (or "fetches") the data from this location every 30 seconds.
To securely allow data fetches from Google, you can use one of the following authentication options:
- Basic authentication (username and password)
- Specific headers to add in the request
Tip: If you choose to set the authentication, please provide the details to Transit support team.
Push
You can actively transfer, or “push,” your data to Google with push delivery. With push delivery, you set up automatic uploads of your GTFS-realtime via HTTP POST, using OAuth2.0 authentication to ensure the security of your realtime feed.
To provide users with the most accurate and up-to-date transit information possible, we recommend that you push realtime updates frequently. Ideally, you should push trip update and vehicle position data every 30 seconds and service alert data every 30 seconds to 2 minutes.
Tip: If you set up push delivery before 2023, your setup uses a different OAuth method. To ensure that your feed pushes continue to work, update the push setup to the new method described below.
Before you begin- One Google Account registered in Transit Partner Dashboard
- One Google Account that can open Google Cloud
- The realtime feed file you want to push to Transit Partner Dashboard
- On the left under the "APIs & Services" tab, click Credentials.
- At the top, click Create Credentials
Service account.
- In the "Service account name" field, enter a name.
- Click Create and continue
Done.
- On the Google Cloud console, click Menu
IAM & Admin.
- On the left, click Service Accounts
Add Key.
- Under "Key type," select JSON.
- Click Create.
- To add the service account as a user to the Transit Partner Dashboard, click Share this account
.
- In the "Invite others to" field, enter the service account email.
- To push new realtime feeds, select Writer or Owner.
- Click Invite.
- realtime_feed_id: The ID of the realtime feed being uploaded
- file: The uploaded GTFS-RT file content
#!/usr/bin/env python3
import requests
from google.oauth2 import service_account
from google.auth.transport.requests import AuthorizedSession
SCOPES = ["https://www.googleapis.com/auth/partnerdash.upload"]
SERVICE_ACCOUNT_FILE = 'service-account-key.json'
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
form = {'realtime_feed_id': '[REALTIME_FEED_NAME]'}
files = {'file': open("feed_version.pb", 'rb')}
req = requests.Request( 'POST', 'https://partnerdash.google.com/push-upload',data=form, files=files).prepare()
authed_session = AuthorizedSession(credentials)
resp = authed_session.request(url="https://partnerdash.google.com/push-upload",method="POST",
data=req.body,
headers={
'Content-Length': req.headers["Content-Length"],
'Content-Type': req.headers["Content-Type"]})
print(resp.headers)
print(resp.reason)
print(resp.raise_for_status())