Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Publishing API & Continuous Deployment on Android

Publishing API & Continuous Deployment on Android

Presented at Droidcon Italy 2017

Júlio Zynger

April 07, 2017
Tweet

More Decks by Júlio Zynger

Other Decks in Technology

Transcript

  1. Google Play Developer API * • Subscriptions and In-App Purchases

    API ◦ In-App Products ◦ Product entitlements ◦ Recurring sales and subscriptions • Publishing API ◦ Create and modify apps’ Listings ◦ Upload new APKs ◦ APK promotion to distribution tracks (alpha, beta, staged rollout and production) • Reviews API ◦ List and answer reviews * quota: 200k requests/day
  2. Google Developer Console Enabling Google Play Android Developer API *

    * create a project on the console if you haven’t yet * panel Library https://console.developers.google.com/apis
  3. Google Developer Console Getting the service account key * panel

    Credentials https://console.developers.google.com/apis
  4. Google Play Store Console Link the app to the created

    project to access the API https://play.google.com/apps/publish
  5. Google Play Store Console Grant access to the service account

    https://play.google.com/apps/publish * check out for the address present on the client_email field in the JSON key
  6. Configuring the dependency Instantiating GoogleCredential NetHttpTransport http = GoogleNetHttpTransport.newTrustedTransport(); JacksonFactory

    json = JacksonFactory.getDefaultInstance(); Set<String> scopes = Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER); File secretFile = new File(Constants.SECRET_FILE_PATH); GoogleCredential credential = new GoogleCredential.Builder(). setTransport(http). setJsonFactory(json). setServiceAccountPrivateKeyId(Constants.KEY_ID). setServiceAccountId(Constants.SERVICE_ACCOUNT_EMAIL). setServiceAccountScopes(scopes). setServiceAccountPrivateKeyFromPemFile(secretFile). build(); https://developers.google.com/android-publisher/#publishing
  7. Configuring the dependency Instantiating GoogleCredential NetHttpTransport http = GoogleNetHttpTransport.newTrustedTransport(); JacksonFactory

    json = JacksonFactory.getDefaultInstance(); Set<String> scopes = Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER); File secretFile = new File(Constants.SECRET_FILE_PATH); GoogleCredential credential = new GoogleCredential.Builder(). setTransport(http). setJsonFactory(json). setServiceAccountPrivateKeyId(Constants.KEY_ID). setServiceAccountId(Constants.SERVICE_ACCOUNT_EMAIL). setServiceAccountScopes(scopes). setServiceAccountPrivateKeyFromPemFile(secretFile). build(); https://developers.google.com/android-publisher/#publishing setServiceAccountPrivateKeyId(Constants.KEY_ID). setServiceAccountId(Constants.SERVICE_ACCOUNT_EMAIL). setServiceAccountPrivateKeyFromPemFile(secretFile). private_key_id client_email private_key (.pem)
  8. Configuring the dependency Instantiating AndroidPublisher NetHttpTransport http = GoogleNetHttpTransport.newTrustedTransport(); JacksonFactory

    json = JacksonFactory.getDefaultInstance(); GoogleCredential credential = ... AndroidPublisher publisher = new AndroidPublisher.Builder(http, json, credential). setApplicationName(PACKAGE). build(); https://developers.google.com/android-publisher/#publishing
  9. AppEdits AndroidPublisher publisher = ... Edits edits = publisher.edits(); //

    insert, get, delete AppEdit appEdit = edits.insert(PACKAGE, null).execute(); String transactionId = appEdit.getId(); ... ... https://developers.google.com/android-publisher/#publishing
  10. AppEdits validate and commit AndroidPublisher publisher = ... Edits edits

    = publisher.edits(); // insert, get, delete AppEdit appEdit = edits.insert(PACKAGE, null).execute(); String transactionId = appEdit.getId(); ... ... edits.validate(PACKAGE, transactionId).execute(); edits.commit(PACKAGE, transactionId).execute(); https://developers.google.com/android-publisher/#publishing
  11. AppEdits validate and commit AndroidPublisher publisher = ... Edits edits

    = publisher.edits(); // insert, get, delete AppEdit appEdit = edits.insert(PACKAGE, null).execute(); String transactionId = appEdit.getId(); ... ... edits.validate(PACKAGE, transactionId).execute(); edits.commit(PACKAGE, transactionId).execute(); https://developers.google.com/android-publisher/#publishing { "code" : 403, "errors" : [ { "domain" : "androidpublisher", "message" : "The full description for the app is too long for language en-US.", "reason" : "fullDescriptionTooLong" } ], "message" : "The full description for the app is too long for language en-US." }
  12. AppEdits Listings Edits edits = publisher.edits(); Listings listings = edits.listings();

    ListingsListResponse listingsListResponse = listings.list(PACKAGE, transactionId).execute(); // Select the Listing you want to update Listing listing = listingsListResponse.getListings().get(...) listing.setFullDescription(description); listings.update(PACKAGE, transactionId, language, listing).execute(); // ... validate // ... commit https://developers.google.com/android-publisher/#publishing
  13. AppEdits Listings Edits edits = publisher.edits(); Listings listings = edits.listings();

    ListingsListResponse listingsListResponse = listings.list(PACKAGE, transactionId).execute(); // Select the Listing you want to update Listing listing = listingsListResponse.getListings().get(...) listing.setFullDescription(description); listings.update(PACKAGE, transactionId, language, listing).execute(); // ... validate // ... commit https://developers.google.com/android-publisher/#publishing { "fullDescription" : string, "language" : string // e.g. "en-US", "shortDescription" : string, "title" : string, "video" : string }
  14. AppEdits Uploading a new APK Apks apks = edits.apks(); FileContent

    apkContent = new FileContent(APK_MIME_TYPE, apkFile); Apk apk = apks.upload(PACKAGE, transactionId, apkContent).execute(); int version = apk.getVersionCode(); https://developers.google.com/android-publisher/#publishing
  15. AppEdits Tracks Apks apks = edits.apks(); FileContent apkContent = new

    FileContent(APK_MIME_TYPE, apkFile); Apk apk = apks.upload(PACKAGE, transactionId, apkContent).execute(); int version = apk.getVersionCode(); Tracks tracks = edits.tracks(); List<Integer> versions = Collections.singletonList(version); Track track = new Track().setVersionCodes(versions); tracks.update(PACKAGE, transactionId, trackId, track).execute(); https://developers.google.com/android-publisher/#publishing
  16. AppEdits Tracks Apks apks = edits.apks(); FileContent apkContent = new

    FileContent(APK_MIME_TYPE, apkFile); Apk apk = apks.upload(PACKAGE, transactionId, apkContent).execute(); int version = apk.getVersionCode(); Tracks tracks = edits.tracks(); List<Integer> versions = Collections.singletonList(version); Track track = new Track().setVersionCodes(versions); tracks.update(PACKAGE, transactionId, trackId, track).execute(); https://developers.google.com/android-publisher/#publishing “alpha”, “beta”, “rollout” (with userFraction), “production”
  17. AppEdits APKListing Apks apks = edits.apks(); FileContent apkContent = new

    FileContent(APK_MIME_TYPE, apkFile); Apk apk = apks.upload(PACKAGE, transactionId, apkContent).execute(); int version = apk.getVersionCode(); Tracks tracks = edits.tracks(); List<Integer> versions = Collections.singletonList(version); Track track = new Track().setVersionCodes(versions); tracks.update(PACKAGE, transactionId, trackId, track).execute(); Apklistings apklistings = edits.apklistings(); ApkListing whatsnew = new ApkListing().setRecentChanges(whatsNewDescription); apklistings.update(PACKAGE, transactionId, version, language, whatsnew).execute(); https://developers.google.com/android-publisher/#publishing
  18. Reviews AndroidPublisher publisher = ... AndroidPublisher.Reviews reviewsApi = publisher.reviews(); List<Review>

    reviews = reviewsApi.list(PACKAGE).execute().getReviews(); Review specificReview = reviewsApi.get(PACKAGE, reviewId).execute(); ... ... https://developers.google.com/android-publisher/#publishing
  19. Reviews AndroidPublisher publisher = ... AndroidPublisher.Reviews reviewsApi = publisher.reviews(); List<Review>

    reviews = reviewsApi.list(PACKAGE).execute().getReviews(); Review specificReview = reviewsApi.get(PACKAGE, reviewId).execute(); ... ... https://developers.google.com/android-publisher/#publishing { "reviewId" : string, "authorName" : string, "comments" : [ "userComment" : { "text" : string, "starRating" : int, "device" : string, "androidOsVersion" : integer, ... }, "developerComment" : { ... } ] }
  20. Reviews AndroidPublisher publisher = ... AndroidPublisher.Reviews reviewsApi = publisher.reviews(); List<Review>

    reviews = reviewsApi.list(PACKAGE).execute().getReviews(); Review specificReview = reviewsApi.get(PACKAGE, reviewId).execute(); ReviewsReplyRequest replyRequest = new ReviewsReplyRequest().setReplyText(replyText); reviewsApi.reply(PACKAGE, reviewId, replyRequest).execute(); ... ... https://developers.google.com/android-publisher/#publishing