{"id":1300,"date":"2023-05-26T14:01:59","date_gmt":"2023-05-26T14:01:59","guid":{"rendered":"http:\/\/wp.chaoyu.nl\/?p=1300"},"modified":"2023-07-25T00:11:40","modified_gmt":"2023-07-24T22:11:40","slug":"react-native-notes","status":"publish","type":"post","link":"https:\/\/chaoyu.nl\/?p=1300","title":{"rendered":"React Native Notes"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li>create app\n<ul class=\"wp-block-list\">\n<li><code>npx create-expo-app StickerSmash<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>run app\n<ul class=\"wp-block-list\">\n<li><code>cd StickerSmash<\/code><\/li>\n\n\n\n<li><code>npx expo start<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>navigation<\/li>\n\n\n\n<li>authentication<\/li>\n\n\n\n<li>Reach Hooks\n<ul class=\"wp-block-list\">\n<li>useState<\/li>\n\n\n\n<li>useEffect<\/li>\n\n\n\n<li>useContext<\/li>\n\n\n\n<li>useMemo<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>context &amp; Redux<\/li>\n\n\n\n<li>https calls<\/li>\n\n\n\n<li>other UI stuff<\/li>\n<\/ul>\n\n\n\n<p class=\"has-pale-pink-background-color has-background wp-block-paragraph\">Get Oauth2Token use axios<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"javascript\" class=\"language-javascript line-numbers\">import base64 from \"react-native-base64\";\nimport axios from \"axios\";\n\nconst getToken = async () =&gt; {\n  try {\n    const username = \"   \";\n    const password = \"    \";\n    const authHeader = \"Basic \" + base64.encode(<code>${username}:${password}<\/code>);\n    const response = await axios.request({\n      headers: {\n        \"Content-Type\": \"application\/x-www-form-urlencoded\",\n        Authorization: authHeader,\n      },\n      url: \"ords\/dev_apex\/oauth\/token\",\n      method: \"post\",\n      baseURL: \"https:\/\/apex.chaoyu.nl\/\",\n      data: \"grant_type=client_credentials\",\n    });\n    const accessToken = response.data.access_token;\n    return accessToken;\n  } catch (error) {\n    console.error(\"Failed to obtain access token:\", error);\n    throw error;\n  }\n};\n\n\/\/ Usage example\ngetToken()\n  .then((accessToken) =&gt; {\n    console.log(\"Access token:\", accessToken);\n    \/\/ Use the access token for authenticated requests\n  })\n  .catch((error) =&gt; {\n    console.error(\"Failed to obtain access token:\", error);\n  });\n<\/code><\/pre>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">get Oauth2 token with fetch<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"javascript\" class=\"language-javascript line-numbers\">import base64 from \"react-native-base64\";\n\nconst username = \"  \";\nconst password = \"  \";\nconst authHeader = \"Basic \" + base64.encode(<code>${username}:${password}<\/code>);\nfetch(\"https:\/\/apex.chaoyu.nl\/ords\/dev_apex\/oauth\/token\", {\n  method: \"POST\",\n  body: \"grant_type=client_credentials\",\n  headers: {\n    \"Content-Type\": \"application\/x-www-form-urlencoded\",\n    Authorization: authHeader,\n  },\n})\n  .then(function (resp) {\n    \/\/ Return the response as JSON\n    return resp.json();\n  })\n  .then(function (data) {\n    \/\/ Log the API data\n    console.log(\"token\", data);\n  })\n  .catch(function (err) {\n    \/\/ Log any errors\n    console.log(\"something went wrong\", err);\n  });<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Get Oauth2Token use axios get Oauth2 token with fetch<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-1300","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/1300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1300"}],"version-history":[{"count":12,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/1300\/revisions"}],"predecessor-version":[{"id":1320,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/1300\/revisions\/1320"}],"wp:attachment":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}