Browse Source

Google API functionality

Summary:
  - Running the figwheel-main server using the `dev` build opens the browser which gives a `Failed to load resource: the server responded with a status of 401 ()`

  - Clicking on the oauth end point url from line number 28 within core.cljs that opens a new browser page with the access token.

  - Checking the chrome console for any errors  which changed from CORS error that I was getting previously, to no errors.

  - Making changes within the core.cljs to println something and checking for hot reloading. This doesn't work,

Test Plan: Run figwheel-main via M-x cider-jack-in-cljs followed by :dev build using emacs.

Reviewers: sid

Reviewed By: sid

Subscribers: sid

Maniphest Tasks: T69

Differential Revision: https://fab.leap-os.com/D23
master
sahabaishakhi 5 years ago
parent
commit
7db734eabf
1 changed files with 19 additions and 11 deletions
  1. +19
    -11
      src/cljs/googlefit-api-test/core.cljs

+ 19
- 11
src/cljs/googlefit-api-test/core.cljs View File

@@ -1,6 +1,5 @@
(ns googlefit-api-test.core
(:require [goog.dom :as gdom]
[reagent.core :as r]))
(:require [reagent.core :as r]))

(enable-console-print!)

@@ -10,15 +9,23 @@

(println fragment-string)

(def xhr (js/XMLHttpRequest.))

(.open xhr "GET" (str "https://www.googleapis.com/fitness/v1/users/me/dataSources" fragment-string) true)

(. xhr send)

(println (.-status xhr))

;; (set! (. xhr onreadystatechange) (fn [] (js/console.log (.response xhr))))
(let [xhr (js/XMLHttpRequest.)]
(set!
(.-onreadystatechange xhr)
(fn []
(when
(and
(= (.-readyState xhr) 4)
(= (.-status xhr) 200)
(js/console.log (str "Response = " (.-response xhr)))))))
;; (.open xhr "GET" (str "https://www.googleapis.com/fitness/v1/users/me/dataSources?" fragment-string) true)
(.open xhr "POST" (str "https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate?" fragment-string))
(.setRequestHeader xhr "Content-Type" "application/json")
(.send xhr (.stringify js/JSON (clj->js
{"aggregateBy" [{"dataSourceId" "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps"}]
"bucketByTime" {"durationMillis" 86400000}
"startTimeMillis" 1591149600000
"endTimeMillis" 1591322400000}))))

(defn appended-container [target]
(let [oauth2-end-point "https://accounts.google.com/o/oauth2/v2/auth?scope=https%3A//www.googleapis.com/auth/fitness.activity.read&include_granted_scopes=true&response_type=token&redirect_uri=http%3A//localhost%3A9500/tokenpage&client_id=857819587666-2pm3q0sv9lvmv697afm0k6jblgvtjon9.apps.googleusercontent.com"
@@ -52,3 +59,4 @@
(r/render-component
[oauth-body]
(appended-container (. js/document (getElementById "app"))))


Loading…
Cancel
Save