<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Roy Tsai on Medium]]></title>
        <description><![CDATA[Stories by Roy Tsai on Medium]]></description>
        <link>https://medium.com/@yozora.sc?source=rss-ede81e7df972------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*eF4DEuFmLTNAI8lM.jpg</url>
            <title>Stories by Roy Tsai on Medium</title>
            <link>https://medium.com/@yozora.sc?source=rss-ede81e7df972------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 13:54:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yozora.sc/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[About usage token]]></title>
            <link>https://medium.com/@yozora.sc/about-usage-token-269c14744c2f?source=rss-ede81e7df972------2</link>
            <guid isPermaLink="false">https://medium.com/p/269c14744c2f</guid>
            <dc:creator><![CDATA[Roy Tsai]]></dc:creator>
            <pubDate>Tue, 03 Nov 2026 06:41:45 GMT</pubDate>
            <atom:updated>2026-11-03T06:41:45.654Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pGQjU5vgNMa541JXCnFRaw.png" /></figure><p>Have you ever actually looked into where your tokens go when running AI agents or coding assistants? I recently audited my usage and realized I burned through 4.4 billion (4.4B) tokens over the past few months. Once I dug into the breakdown, I saw just how much room there was for optimization.</p><p>At first glance, 4.4B looks like a crazy amount of output. In reality, it was almost the opposite. The actual new code written was just a tiny fraction; over 90% of those tokens were simply context cache reads being replayed over and over. I had fallen into the classic long-session trap: keeping a single thread alive from initial planning and coding all the way through testing and bug fixes. Once the context ballooned to near 100k tokens, every single command or quick confirmation meant dragging that entire 100k-token history along for the ride. And whenever auto-compaction kicked in to free up space, losing those fine details only caused hallucinations and more redundant file reads, creating an even slower cycle.</p><p>To fix this, I made a few straightforward changes to my workflow. First, I committed to “one task, one session.” Once a milestone passes type checks, I document the state in an issue and start a fresh session rather than dragging out a massive conversation. Second, I stopped letting the main agent crawl the entire repo — disposable explore sub-agents now handle wide searches and only bring back file paths and key findings. I also capped terminal outputs so hundreds of lines of build logs wouldn’t pollute future turns, and packaged repetitive project rules into modular skills and clear SOPs so the agent stays on track without constant prompt reminders.</p><p>Working with agentic workflows taught me that the real bottleneck usually isn’t how smart the model is — it’s how disciplined you are with context boundaries. Context is high-speed RAM, not infinite disk space. When you actively clear it out, everything runs noticeably faster and cleaner.</p><p>A quick shoutout to OpenCode’s policy at the time, which kept my actual bill at $0 — basically a free masterclass in workflow optimization. The real expense was never the money; it was all the time lost waiting for billions of tokens to replay.</p><p>Do you track your token usage when building with AI? How do you prevent your agent sessions from bloating?</p><p>#AIAgents #OpenCode #SoftwareEngineering #DeveloperProductivity #TokenOptimization</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=269c14744c2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[越南-峴港]]></title>
            <link>https://medium.com/@yozora.sc/%E8%B6%8A%E5%8D%97-%E5%B3%B4%E6%B8%AF-50bcede3b9a3?source=rss-ede81e7df972------2</link>
            <guid isPermaLink="false">https://medium.com/p/50bcede3b9a3</guid>
            <dc:creator><![CDATA[Roy Tsai]]></dc:creator>
            <pubDate>Tue, 27 Oct 2026 02:37:47 GMT</pubDate>
            <atom:updated>2026-10-27T02:37:47.884Z</atom:updated>
            <content:encoded><![CDATA[<p>最近去了一趟峴港。</p><p>發現很多在地人，假日會在傳統的小店喝咖啡。看新聞滑手機、跟朋友聊天、發呆看街景、非常悠閒。店內的椅子都面朝街道馬路、人們在意的不是塵土飛揚和機車廢氣，而是車流、行人和平凡的日常。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GLBwCJIYLj29pON5_GVyqw.jpeg" /><figcaption>AI生成概念圖</figcaption></figure><p>越南本地有很多連鎖咖啡廳，比較常見的是Highlands Coffee，去咖啡廳的人不多，但會很容易看到一些遠端工作者，跨國的Remote工作似乎蠻多的。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*phnm8F6Wj9f6hX-Bp6bizQ.jpeg" /></figure><p>用中文溝通可能大於英文，年輕人和小朋友非常多、能真實感受到越南這個發展中的國家的潛力、機會和可能性。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BVUvMLE3YQDeDYNNqS68sg.jpeg" /><figcaption>拍到彩虹</figcaption></figure><p>另外、交通真的可怕😅。父母騎機車載2個以上的小朋友也很多、機車與氣車之間的距離非常近，過馬路要慢慢前進，看到路上有紅綠燈會有點感動，但是沒有緩衝的黃燈。</p><p>近一年來、看著新聞放送AI模型迭代超前、股市泡沫風險，好像全世界已經變了。但走進街頭小店買東西，攤販拿出手機打字比手畫腳，或是直接在計算機上按個數字，交易就完成了。</p><p>某些領域焦慮的『AI數位轉型』，跟市井小民生活裡的真實需求相比仍有巨大溫差。目前的很多時候，不需要多強的模型，用簡單直接的方法能解決眼前的需求就足夠。</p><p>不過對習慣把 AI 當日常工具的人來說，拍照分析確實很方便。隨手拍下街頭小吃、解說在地吃法，或是拍下商品標籤，除了翻譯之外，還能一起計算組合特價，都幫了大忙。未來這些能力直接跑在手機的邊緣端，反應一定更快、更無感；</p><p>但也會想，如果都完全仰賴AI，旅行中那種帶著笨拙比手畫腳的人際溫度，是不是也會慢慢少了一些。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*bpcRvQEe9Lx9YU586IAhEQ.jpeg" /><figcaption>計算機和比手畫腳的小攤，法國麵包不錯吃</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50bcede3b9a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Unassuming Baker]]></title>
            <link>https://medium.com/@yozora.sc/the-unassuming-baker-9eb115949a05?source=rss-ede81e7df972------2</link>
            <guid isPermaLink="false">https://medium.com/p/9eb115949a05</guid>
            <category><![CDATA[english-learning]]></category>
            <category><![CDATA[attitude]]></category>
            <category><![CDATA[vocabulary]]></category>
            <category><![CDATA[ielts]]></category>
            <dc:creator><![CDATA[Roy Tsai]]></dc:creator>
            <pubDate>Mon, 17 Feb 2025 07:07:34 GMT</pubDate>
            <atom:updated>2025-04-25T13:08:49.674Z</atom:updated>
            <content:encoded><![CDATA[<h3>[IELTS] The Unassuming Baker</h3><p>IELTS — Vocabuily Unit 1 Attitude</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cO2fZz7L8V_wpmUv" /></figure><p>In our small town, <strong>stereotypes </strong>unfortunately weren’t uncommon. Many held a <strong>pessimistic </strong>view of newcomers, and when Mr. Abernathy moved in to open his bakery, some even considered him a <strong>nuisance</strong>. He was a quiet man, and his initial demeanor was somewhat indifferent, leading some to insult him behind his back, calling him <strong>stingy </strong>and <strong>arrogant </strong>even before trying his bread.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Vv-DIajt27DVybdj" /></figure><p>Sarah, however, was curious. She didn’t believe in <strong>stereotypes </strong>and found herself <strong>admiring </strong>Mr. Abernathy’s <strong>diligence</strong>. Every morning, before sunrise, the smell of baking bread would waft through the streets, a testament to his hard work. She felt a <strong>sentiment </strong>of respect growing for him.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wV_U2yDQcEOZ658Z" /></figure><p>One day, Sarah decided to embrace the opportunity to get to know him. She walked into the bakery, her heart filled with <strong>cheerful </strong>anticipation. Inside, Mr. Abernathy was <strong>meticulously </strong>arranging pastries. He was <strong>discrete </strong>in his movements, each action <strong>precise </strong>and careful.</p><p>“Good morning!” Sarah greeted him, her voice <strong>assertive </strong>yet friendly.</p><p>Mr. Abernathy looked up, <strong>a flicker of</strong> surprise in his eyes. He offered a shy smile and returned her greeting. Sarah learned that his quietness wasn’t arrogance, but rather a <strong>devout </strong>focus on his craft. He spoke with willpower about his passion for baking, and his <strong>conscience </strong>clearly guided him to use only the <strong>finest ingredients</strong>.</p><p>As they talked, Sarah discovered he wasn’t <strong>stingy </strong>at all, but simply careful and discrete with his resources, ensuring the quality of his products. He wasn’t <strong>indifferent </strong>to the town, but rather observing and trying to understand the community before fully opening up.</p><p>Sarah left the bakery with a warm loaf of bread and a heart full of grateful understanding. She realized how <strong>naive </strong>she had been to even slightly consider the <strong>stereotypes </strong>others had created. She was now <strong>optimistic </strong>about Mr. Abernathy’s bakery becoming a beloved part of the town.</p><p>However, not everyone was as open-minded as Sarah. Old Mr. Grumbles remained pessimistic. He would often <strong>harass</strong> Mr. Abernathy with complaints, finding ways to <strong>irritate </strong>him. One day, finding a slightly burnt crust on his pie, Mr. Grumbles flew into an <strong>indignant </strong>rage, loudly declaring it was disgusting and that Mr. Abernathy was a <strong>wretched </strong>and <strong>unpleasant </strong>baker who should be <strong>despised</strong>.</p><p>Mr. Abernathy, though <strong>initially </strong>saddened by Mr. Grumbles’ outburst, did not <strong>lament </strong>for long. He knew that true appreciation comes from <strong>genuine hearts</strong>, like Sarah’s, who were fond of his baking and saw beyond stereotypes. He continued to bake with <strong>diligence </strong>and <strong>cheerfulness</strong>, <strong>confident </strong>that his passion and hard work would eventually win over even the most <strong>pessimistic </strong>and <strong>indifferent </strong>hearts in town.</p><p>stereotype (刻板印象): 對特定群體過於簡化和普遍化的看法。</p><p>admire (欽佩): 對某人或某事感到尊敬和讚賞。</p><p>pessimistic (悲觀的): 傾向於看到事情的負面方面。</p><p>diligence (勤奮): 持續努力和專注於工作或目標。</p><p>sentiment (情感): 對某事物的感覺或看法。</p><p>harass (騷擾): 持續地煩擾或威脅某人。</p><p>discrete (謹慎的): 小心且避免引起注意，尤其是在言行方面。</p><p>willpower (意志力): 控制自己行為和克服誘惑的能力。</p><p>curious (好奇的): 渴望學習或知道更多事情。</p><p>unpleasant (令人不愉快的): 不友善、不舒服或令人反感的。</p><p>fond (喜愛的): 對某人或某事感到溫柔的喜愛和 affection。</p><p>nuisance (討厭的人/物): 引起麻煩或煩惱的人或物。</p><p>assertive (堅定的): 自信且果斷地表達自己的意見或要求。</p><p>insult (侮辱): 言語或行為冒犯或貶低某人。</p><p>cheerful (愉快的): 快樂且樂觀的。</p><p>stingy (小氣的): 不願意花錢或給予。</p><p>embrace (接受/擁抱): 樂意接受或支持某事，或擁抱某人。</p><p>irritate ( раздражать): 使某人生氣或惱怒。</p><p>devout (虔誠的): 對宗教或信仰非常忠誠和熱情。</p><p>optimistic (樂觀的): 傾向於對未來或成功抱持希望和信心。</p><p>lament ( 哀悼/嘆息): 表達悲傷、遺憾或失望。</p><p>conscience (良心): 內在的道德指南，判斷行為的對錯。</p><p>disgust (厭惡): 強烈的反感或厭惡感。</p><p>indifferent (漠不關心的): 對某事沒有興趣或不關心。</p><p>arrogant (傲慢的): 過分自信且自以為是。</p><p>grateful (感激的): 因某事而感到感謝。</p><p>indignant (憤慨的): 因不公平或錯誤的事情而感到憤怒。</p><p>despise (鄙視): 強烈地厭惡或看不起某人或某事。</p><p>wretched (可憐的): 非常不幸或悲慘的。</p><p>naive (天真的): 缺乏經驗、智慧或判斷力。</p><p><strong>meticulously (</strong>精心<strong>)</strong></p><p><strong>precise (精確)</strong></p><p><strong>a flicker of (一閃而逝)</strong></p><p><strong>finest ingredients (最好的原料)</strong></p><p><strong>genuine hearts (真誠的心)</strong></p><h4>Vocabulary Source:</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fag2WI2AmKNY%3Flist%3DPLOB7G19x6JpMfLQGNgpMWkrhBGzGRQ2eb&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dag2WI2AmKNY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fag2WI2AmKNY%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/23ec4c7378c0186c00e9b4de954296b2/href">https://medium.com/media/23ec4c7378c0186c00e9b4de954296b2/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9eb115949a05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Google AI Studio for speech-to-text conversion]]></title>
            <link>https://medium.com/@yozora.sc/using-google-ai-studio-for-speech-to-text-conversion-2476275029f1?source=rss-ede81e7df972------2</link>
            <guid isPermaLink="false">https://medium.com/p/2476275029f1</guid>
            <category><![CDATA[ghosts]]></category>
            <category><![CDATA[voice-assistant]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[airbnb]]></category>
            <dc:creator><![CDATA[Roy Tsai]]></dc:creator>
            <pubDate>Wed, 12 Feb 2025 15:12:18 GMT</pubDate>
            <atom:updated>2025-02-12T15:16:34.407Z</atom:updated>
            <content:encoded><![CDATA[<h4>I saw this story on YouTube…</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FDkDrvaK3tRA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fshorts%2FDkDrvaK3tRA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FDkDrvaK3tRA%2Fhq2.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8328544c45fdfc3f6dccb1210fcab2ae/href">https://medium.com/media/8328544c45fdfc3f6dccb1210fcab2ae/href</a></iframe><p>It very interesting. Then, I wanted to convert the content into text after obtaining the audio file using <a href="https://x.com/i/grok?text=recording%20software">recording software</a> or other legal ways.</p><p>Go to Google AI Studio:<br><a href="https://aistudio.google.com/u/1/prompts/new_chat">https://aistudio.google.com/u/1/prompts/new_chat</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cOggVJsfq1u5jWbsZot6kw.png" /></figure><p>Select “Upload File” in the bottom right corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*0adqei7mmNICC7dWWuesMg.png" /></figure><p>Once the upload is complete, you can enter text for conversion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bDBJgiZc2p7C-421zTFJSw.png" /></figure><p>The results will vary depending on the selected model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*NVI-mvstiYnlEPy0kbSE3g.png" /></figure><h4><strong>Gemini 2.0 Flash Thinking Experimental 01–21</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fUlJyCTjV6ZcEpjjWjqplg.png" /></figure><h4><strong>Gemini 2.0 Pro Experimental 02–05</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QmqJ665mXQi7A12QVOqjPg.png" /></figure><p>We can see that Gemini 2.0 Flash Thinking is indeed seriously ‘thinking.’ Although there are still some shortcomings at this stage, it remains usable enough.</p><p>And i prefer<strong> Gemini 2.0 Flash Thinking Experimental. </strong>Below are all the voice text conversations.”</p><pre>0:00 one day, a customer calls us and says, they want a full refund.<br>00:04 We say, why do you want a full refund?<br>00:05 They said because the house is haunted and there&#39;s a ghost in the house.<br>00:09 And we&#39;re like, okay, well we have to adjudicate this.<br>00:11 So we call the host and all the host has to do is deny it because there&#39;s no photo evidence of ghost.<br>00:17 Unfortunately, the host confirms the ghost.<br>00:21 Says that it&#39;s a friendly ghost named Stanley and that the ghost Stanley is in the listening description.<br>00:27 We read the listening description.<br>00:29 Stanley is mentioned.<br>00:30 So we go back to the guests and the guests says, yes, we knew about Stanley.<br>00:34 That&#39;s why we booked it, but Stanley has been harassing us all night.<br>00:39 How do you adjudicate that?<br>00:40 So I guess the point is in this new economy built on trust, you can only imagine the kind of issues you deal with.<br>00:46 There is no playbook for this stuff.<br>00:47 Okay, we&#39;re going to sneak in, we&#39;re going to sneak in only one question right there if we can get get a microphone to you.<br>00:52 Yeah.<br>00:53 I&#39;m Leila.<br>00:53 I&#39;ve come to attend this from UK.<br>00:55 I&#39;m living in a big chain for last four years.<br>00:59 And now that I come here in New York and they said there&#39;s mandatory charge for $20 for the bar and $10 for some other kitchen.<br>01:08 I said I don&#39;t drink.<br>01:09 They said, well, it is now the new trend.<br>01:12 Are you going to start this also?<br>01:14 Because I&#39;m going to shift on Airbnb because of this, not that it $20, but it&#39;s just that I don&#39;t like the idea why you&#39;re forcing me to pay those $30 every day.<br>01:24 Now, we won&#39;t do that.<br>01:25 Um, your hotels and airlines uh kind of realized a business model where if you basically add on certain fees at the end, they basically are pure profit that goes to the bottom line.<br>01:35 And so that&#39;s obviously why when you book an airline, you&#39;ll pay for an extra baggage and hotels.<br>01:40 So, but no, we aren&#39;t going to do that.<br>01:41 I think one of the big powers is to try to flatten the cost model.<br>01:45 Okay.<br>01:46 Um, please join me.<br>01:48 You know, you know what?<br>01:48 I see a question right there.<br>01:49 Let&#39;s go let&#39;s go to we&#39;re going to sneak one more in uh because I know everybody&#39;s got to get to lunch and I know we have so many fabulous groundbreakers here.<br>01:55 Thanks a lot.<br>01:56 I&#39;m Sylvie.<br>01:57 You answered my first question about the fact that you book your own home.<br>02:02 My second question, it&#39;s why made you decide to go in the policy of buying hotels?<br>02:09 Buying hotels?<br>02:10 You said that you bought you know one hotel.<br>02:11 He has he has he bought hotels.<br>02:12 He&#39;s bought a a company called Hotel Tonight, which is effectively a platform to to to book hotels.<br>02:18 Yeah.<br>02:19 I can I can answer why we bought Hotel tonight if that&#39;s the question.<br>02:21 So, um, well, it&#39;s a funny story because when we launched Airbnb, actually, the original name was, and I&#39;ll try to say this quickly, air bed and breakfast.<br>02:30 I the short version was it was 2007 and I was totally broke, living with my roommate in San Francisco.<br>02:36 We couldn&#39;t afford to pay rent.<br>02:37 There was a design conference come to San Francisco.<br>02:40 All the hotels are sold out.<br>02:41 And we had this idea, let&#39;s create a bed and breakfast for design conference.<br>02:45 I didn&#39;t have any beds, but Joe had three airbeds.<br>02:47 We inflated them.<br>02:48 We called it airbed and breakfast.com.<br>02:50 Our original tagline was airbed and breakfast, a cheap, affordable alternative to a hotel.<br>02:56 And we never ever imagined we would ever have hotels in Airbnb.<br>03:00 And um, 10 years later, we we were starting to realize that the number with with people go to Airbnb and they abandon Airbnb and they go to another website.<br>03:10 The websites they were going to were hotels and that there were a whole bunch of people that will only book Airbnbs.<br>03:15 But there&#39;s a bunch of other people that will sometimes book Airbnbs with their family and friends, but if they&#39;re in business travel, they&#39;ll book a hotel.<br>03:21 We thought it was just completely crazy to make you go to a different website when we already have the customer.<br>03:27 But we didn&#39;t want to add a bunch of chain hotels.<br>03:30 But I knew Sam Shank, the founder of Hotel Tonight.<br>03:33 He was very like very consistent with our methodology, focus on boutique hotels, small business owners, which are very similar to many of our hosts.<br>03:41 And so we thought this is an incredible partnership and that&#39;s why we did it.<br>03:46 Okay.<br>03:47 Brian Chesky everybody, please join me in thanking him.</pre><p>If you found this article helpful or useful, please give it some claps. This is a basic setup, and there might be inaccuracies or unclear parts in the process. If you have any other questions, feel free to leave a comment or send me a message : )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2476275029f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Post Text to Threads Using n8n]]></title>
            <link>https://medium.com/@yozora.sc/how-to-post-text-to-threads-using-n8n-8062bbdf42db?source=rss-ede81e7df972------2</link>
            <guid isPermaLink="false">https://medium.com/p/8062bbdf42db</guid>
            <category><![CDATA[threads]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[n8n]]></category>
            <category><![CDATA[meta]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Roy Tsai]]></dc:creator>
            <pubDate>Fri, 07 Feb 2025 07:27:29 GMT</pubDate>
            <atom:updated>2025-02-07T07:27:29.694Z</atom:updated>
            <content:encoded><![CDATA[<p>The goal is to integrate this method into your own n8n workflow. Although there might be room for improvement, we’ll refine it later.</p><p>Here’s what you need to do first:</p><p><strong>A. Preliminary Setup</strong></p><ul><li>Long-Lived Tokens — Threads API — Documentation — Meta for Developers (developers.facebook.com)</li><li>Short-lived tokens can be exchanged for long-lived tokens.</li></ul><p><a href="https://developers.facebook.com/docs/threads/get-started/long-lived-tokens/">Long-Lived Tokens - Threads API - Documentation - Meta for Developers</a></p><p><strong>B. Understanding the Thread Posting Process</strong></p><ul><li>Posts — Threads API — Documentation — Meta for Developers (developers.facebook.com)</li><li>Publish a single image, video, text, or carousel post on Threads.</li></ul><p><a href="https://developers.facebook.com/docs/threads/posts#single-thread-posts">Posts - Threads API - Documentation - Meta for Developers</a></p><p>After consulting these resources, you’ll understand that:</p><ul><li>Use the token (Long-Lived Access Tokens) to first obtain the ‘<a href="https://x.com/i/grok?text=Thread%20User%20ID">Thread User ID</a>’.</li><li>Use the ‘Thread User ID’ to create a ‘<a href="https://x.com/i/grok?text=Container%20ID">Container ID</a>’ along with the content you want to post.</li><li>Use the ‘Container ID’ to make posts on Threads.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ytPk6Qv4Ugtn2IGVfrvqXg.png" /></figure><p>Once you’ve set up the Long-Lived Token and the Meta develop console:</p><h4>Get thread userID</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*MdLklnu2CPIBmR9GUPy3gA.png" /></figure><ul><li>Refer to the API documentation to assemble the URL:</li><li><a href="https://graph.threads.net/v1.0/me?access_token={token}&amp;%249=THREADS&amp;debug=all&amp;fields=id%2Cname&amp;format=json&amp;method=get&amp;origin_graph_explorer=1&amp;pretty=0&amp;suppress_http_code=1&amp;transport=cors">https://graph.threads.net/v1.0/me?access_token=<strong>{token}</strong>&amp;%249=THREADS&amp;debug=all&amp;fields=id%2Cname&amp;format=json&amp;method=get&amp;origin_graph_explorer=1&amp;pretty=0&amp;suppress_http_code=1&amp;transport=cors</a></li><li>Replace<strong> {token} </strong>and configure the GET request in an n8n <a href="https://x.com/i/grok?text=HTTP%20node">HTTP node</a>.</li></ul><h4>Fromat for Create Container ID</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*Jljr02kgB2cGZCSCJ77Kxg.png" /></figure><ul><li>The purpose is to use parameters returned from the first HTTP request to replace parameters in the URL for the next step.</li></ul><h4>Create threads contain id</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*Zz6BNq33jfq8C0Zqnvh47A.png" /></figure><ul><li>Assemble the URL, use an n8n HTTP node, and set it to <a href="https://x.com/i/grok?text=POST">POST</a>.</li></ul><h4>Format for get container id</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*QiORgxDoGvIY1mYg2VXk5g.png" /></figure><ul><li>Combine the returned container ID parameter into the n8n HTTP POST to create a Threads post.</li></ul><h4>Post contain to threads</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*RUSnmSPJE8iMZNIZXwlV3g.png" /></figure><p>Here’s the additional part you mentioned that wasn’t translated.</p><p>This completes the setup. Note that in Meta’s Example Request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/208/1*MD2moJpLMeDHH6axp572Uw.png" /></figure><p>This completes the setup. Note that in Meta’s Example Request:</p><ul><li>The URL does not end with a period (‘.’).</li><li>The parameter is not ‘access_tokenimages’.</li></ul><p>If you found this article helpful or useful, please give it some claps. This is a basic setup, and there might be inaccuracies or unclear parts in the process. If you have any other questions, feel free to leave a comment or send me a message : )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8062bbdf42db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use n8n for an automated process that post on X with Gemini Flash Thinking]]></title>
            <link>https://medium.com/@yozora.sc/use-n8n-for-an-automated-process-that-post-on-x-with-gemini-2-0-flash-thinking-2d9b8fe04903?source=rss-ede81e7df972------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d9b8fe04903</guid>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[n8n]]></category>
            <category><![CDATA[yahoo]]></category>
            <category><![CDATA[workflow]]></category>
            <dc:creator><![CDATA[Roy Tsai]]></dc:creator>
            <pubDate>Mon, 03 Feb 2025 16:02:58 GMT</pubDate>
            <atom:updated>2025-04-06T12:33:52.253Z</atom:updated>
            <content:encoded><![CDATA[<p>This is an n8n workflow to automatically fetch Yahoo Finance news, summarize using Gemini, and post to X (Twitter).。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IBgUl7AQGTaGbaVk-Ug-eA.png" /></figure><h4>Step1.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*dAa4EG-Y2Ujfd_SGzvjeiw.png" /></figure><p>Uses a time trigger, defaulting to midnight to fetch news and format the data. It then uses a Code node to prepend “<a href="https://www.google.com/url?sa=E&amp;q=https%3A%2F%2Ftw.news.yahoo.com%2F">https://tw.news.yahoo.com/</a>&quot; to each link, ensuring URLs are accessible in Step2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*DbKZOzJsxZqeF6L_NkqEGA.png" /></figure><h4>Step2.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*vZQZ1sYYVWTRne__2rIgWQ.png" /></figure><p>News pages are structured with a homepage and separate article links. This step first clicks the homepage to extract titles and URLs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*7jyCkVsp8Ck0rB3___C_Ow.png" /></figure><p>Then, it accesses each link to retrieve the article content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*0O8CCz-LjBH6xkytEL4wvw.png" /></figure><p>Finally, a Code node is used to format the data, retaining only specified strings and removing URLs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*QMLDAVAIRtB4RMwWCz7Gbw.png" /></figure><h4>Step3.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*mTJRe4C2AJ0COmpUPNX_Mg.png" /></figure><p>After news data preparation, this step merges the original data with the prepared article content, readying it for Gemini 2.0 Thinking.</p><h4>Step4.</h4><p>This involves acquiring the necessary credentials: OAuth 2.0 authentication fields from the X API console and the API Key for Gemini 2.0 flash thinking.</p><p><strong>Refer:</strong></p><ul><li><a href="https://developer.x.com/en/portal/dashboard">JavaScript is not available.</a></li><li><a href="https://aistudio.google.com/prompts/new_chat">Sign in</a></li></ul><h4>Step5.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xAGmE-Qc-Lu3ezInXb5mtw.png" /></figure><p>A Code node merges the data into a format readable by the Basic LLM Chain. The workflow then uses two LLMs: the first for analysis and the second for data format processing, before sending the processed information to X for posting.</p><p>If you found this article helpful or useful, please give it some claps. This is a basic setup, and there might be inaccuracies or unclear parts in the process. If you have any other questions, feel free to leave a comment or send me a message : )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d9b8fe04903" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying n8n with Azure Container Apps and Azure PostgreSQL.]]></title>
            <link>https://medium.com/@yozora.sc/deploying-n8n-with-azure-container-apps-and-azure-postgresql-54b79215ffcc?source=rss-ede81e7df972------2</link>
            <guid isPermaLink="false">https://medium.com/p/54b79215ffcc</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[workflow-automation]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Roy Tsai]]></dc:creator>
            <pubDate>Fri, 31 Jan 2025 17:17:10 GMT</pubDate>
            <atom:updated>2025-01-31T17:17:10.439Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wclx6Ueik3oj36XZFOXT1A.png" /></figure><p>The purpose of this article is to document the process of setting up n8n with Azure Container Apps and Azure PostgreSQL, hoping to provide some assistance to those undertaking this task. n8n is a software tool for automating workflows.</p><p><a href="https://n8n.io/">n8n.io — a powerful </a><em>Secure and AI-native workflow automation tool for technical people. Insert code when you need it. Full source code and extensibility.</em></p><p><a href="https://n8n.io/">n8n.io - AI workflow automation platform</a></p><h3>1. Preparatory Work</h3><h4><strong>Understand:</strong></h4><ul><li>Read through the official n8n documentation to understand its features and configuration requirements.</li><li>Get familiar with Azure Container Apps to learn how to deploy and manage containerized applications.</li><li>Set up and test connections to Azure PostgreSQL.</li></ul><h3>2. Preparing the n8n Docker Image</h3><h4>Use Docker Hub:</h4><ul><li>Test locally and create an image file.</li><li>Register with Docker Hub to build and deploy the image file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-uS3CcVmnwHKmVs3XJXG4g.png" /></figure><h3>2. Setting Up and Configuring Azure Container Apps</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*hJ043M-PKldu1fzTkoJBzw.png" /></figure><h4>Sync Image from Docker Hub:</h4><ul><li>Pull the n8n image from Docker Hub or n8n’s official repository.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*rECbbRx3liCG3PX1mOsV_w.png" /></figure><h3><strong>Create n8n Azure Share File for Volume Use</strong>:</h3><ul><li>Configure the files and folders as shown below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WbX-n-0xjpyuLTsp3W9Byw.png" /></figure><h4>Set Up n8n’s Directory and File Structure:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*MFAk-9BJDOLGLPLC3MvyjA.png" /></figure><h4>Manually create directories:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZoLegc7F-Yb0oNceOhGTpg.png" /></figure><h4>Mount Volume &amp; Mount Path:<strong> </strong><br><strong>/home/node/.n8n</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*SGXR9tcx_wQrDyfm7tzHGg.png" /></figure><h4><strong>Verify Mounting Success</strong>:</h4><ul><li>Check if the volume has been mounted correctly.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*d25wVvuJazCoydgJDrp7hA.png" /></figure><h3>3. <strong>Setting Up Azure PostgreSQL:</strong></h3><ul><li>Configure Account, Password, and Parameters</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9s66niH43bpDr42tiwX9dA.png" /></figure><h4>Update the p<strong>arameters:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*C-XP1weQsMOl-ZCRONDI-A.png" /></figure><h4>Verify parameters:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X4Wt8nWZddq9TUuSEuMVgQ.png" /></figure><h4>Restart Container and Test Connection</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*9_852eMOv1PmmYF21T-irQ.png" /></figure><p>If you found this article helpful or useful, please give it some claps. This is a basic setup, and there might be inaccuracies or unclear parts in the process. If you have any other questions, feel free to leave a comment or send me a message : )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54b79215ffcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Next.js 與 X API 的驗證和推文範例]]></title>
            <link>https://medium.com/@yozora.sc/next-js-%E8%88%87-x-api-%E7%9A%84%E9%A9%97%E8%AD%89%E5%92%8C%E6%8E%A8%E6%96%87%E7%AF%84%E4%BE%8B-9cd5432fb1ab?source=rss-ede81e7df972------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cd5432fb1ab</guid>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[twitter]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[xapi]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Roy Tsai]]></dc:creator>
            <pubDate>Thu, 30 Jan 2025 03:35:22 GMT</pubDate>
            <atom:updated>2025-01-30T03:35:22.132Z</atom:updated>
            <content:encoded><![CDATA[<h4>使用技術</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*QHrWAD4FDLc0J1tv-_STAA.png" /></figure><h4>主要功能</h4><ul><li><strong>認證系統</strong>：/app/api/twitter/auth2/</li><li><strong>推文功能</strong>：/app/api/twitter/</li><li><strong>前端界面</strong>：/app/</li></ul><h4>系統流程</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*PTDa6cPAehtZ5QPFdVkaSg.png" /></figure><h4>.OAuth2.0認證流程</h4><ol><li>使用者點擊登入按鈕</li><li>系統生成 PKCE 挑戰碼和狀態值</li><li>重定向到 Twitter 授權頁面</li><li>使用者授權後返回NextJS</li><li>系統驗證並交換訪問Token</li><li>將Token儲存在 HTTP-only cookies 中</li></ol><h4>.推文發送流程</h4><ol><li>使用者填寫推文內容</li><li>系統使用儲存的訪問Token發送請求</li><li>透過 Twitter API v2 發送推文</li></ol><h4>登入</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*HIjUDe_qa7s43wSt6lBS0A.png" /></figure><h4>登出</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*-Hg0LxAO_YH5IUhWvmfVRw.png" /></figure><h4>範例專案參照</h4><p><a href="https://github.com/YozoraRoy/NextjsForXAPIExample">GitHub - YozoraRoy/NextjsForXAPIExample</a></p><h4>注意</h4><p>1.要先去X Develops 註冊一個app，並選擇web的方式。</p><p>2.參照範例要記得新增一個.env.local</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*apG5XrNL5RS8gmzbAoAQVQ.png" /></figure><p>如果覺得文章不錯或對你有幫助，請幫我多拍幾個手<br>這是一個簡單的設定，可能過程中有誤或者不清楚，有其他問題<br>也歡迎留言或傳訊息給我 : )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cd5432fb1ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[如何使用NextJS佈署到Azure Web Static App ?]]></title>
            <link>https://medium.com/@yozora.sc/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8nextjs%E4%BD%88%E7%BD%B2%E5%88%B0azure-web-static-app-76478fb79665?source=rss-ede81e7df972------2</link>
            <guid isPermaLink="false">https://medium.com/p/76478fb79665</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[azure-static-web-app]]></category>
            <dc:creator><![CDATA[Roy Tsai]]></dc:creator>
            <pubDate>Fri, 24 Jan 2025 09:36:47 GMT</pubDate>
            <atom:updated>2025-01-30T03:24:01.765Z</atom:updated>
            <content:encoded><![CDATA[<h3>如何使用NextJS佈署到Azure Static WebApp ?</h3><p>按照一般微軟的操作教學，遇到了要使用SWA(<a href="https://azure.github.io/static-web-apps-cli/">Static Web Apps CLI</a>)進行佈署，遇到了找不到index.html的的問題。</p><blockquote>Failed to find a default file in the app artifacts folder (.next). Valid default files: index.html,Index.html.</blockquote><p>主要是SWA預設需要這個Index檔案，所以我這邊的解決方式就是建立一個空的Index.html ，並且設定每次編譯的時候，就建立出這個檔案，也就是使用<a href="https://nextjs.org/docs/pages/building-your-application/rendering/static-site-generation">Static Site Generation (SSG)</a>的方式進行。</p><h4>1.建立專案</h4><pre>npx create-next-app@latest my-next-app<br>cd my-next-app</pre><p>init設定好後，選擇使用App Router和TypeScript<br>並且確定可以正常運作</p><pre>npm run dev</pre><h4>2.安裝SWA</h4><pre>npm install -g @azure/static-web-apps-cli</pre><h4>3.SWA初始化</h4><pre> swa init</pre><p>確認裡面的appLocation &amp; outputLocation 參數和值</p><pre>      &quot;nextjs&quot;: {<br>      &quot;appLocation&quot;: &quot;.&quot;,<br>      &quot;outputLocation&quot;: &quot;out&quot;,</pre><h4>4.手動建立staticwebapp.config.json</h4><pre>{<br>    &quot;routes&quot;: [<br>      {<br>        &quot;route&quot;: &quot;/&quot;,<br>        &quot;rewrite&quot;: &quot;/index.html&quot;<br>      },<br>      {<br>        &quot;route&quot;: &quot;/:id&quot;,<br>        &quot;rewrite&quot;: &quot;/index.html&quot;<br>      }<br>    ]<br>  }</pre><h4>4.設定package</h4><p>新增<strong>postbuild</strong>的參數，讓專案建置後產生index檔案</p><pre>  &quot;scripts&quot;: {<br>    &quot;dev&quot;: &quot;next dev --turbopack&quot;,<br>    &quot;build&quot;: &quot;next build&quot;,<br>    &quot;start&quot;: &quot;next start&quot;,<br>    &quot;lint&quot;: &quot;next lint&quot;,<br>    &quot;postbuild&quot;: &quot;node config/postbuild.js&quot; <br>  },</pre><h4>5.設定next.config.js，output &amp; distDir參數和值</h4><pre>import type { NextConfig } from &quot;next&quot;;<br><br>const nextConfig: NextConfig = {<br>  output: &#39;export&#39;,<br>  distDir: &#39;out&#39;, <br>  /* other config options here */<br>};<br><br>export default nextConfig;</pre><h4>6.新增codfig資料夾和新增postbuild.js</h4><p>程式碼請參照範例專案</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/192/1*pFIUYXKWuSCOEsiYHY2LYw.png" /></figure><h4>7.在App的資料夾中建立了API資料夾和動態路由[id]資料夾和page.tsx</h4><p>程式碼請參照範例專案</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*v4loY7PSVLpUffByTCT-Gg.png" /></figure><h4>8. swa build:</h4><pre>Route (app)                              Size     First Load JS<br>┌ ○ /                                    5.55 kB         111 kB<br>├ ○ /_not-found                          982 B           106 kB<br>├ ○ /API                                 594 B           106 kB<br>└ ● /API/[id]                            135 B           106 kB<br>    ├ /API/1<br>    ├ /API/2<br>    ├ /API/3<br>    └ [+197 more paths]<br>+ First Load JS shared by all            105 kB<br>  ├ chunks/4bd1b696-7035412d470bfb0e.js  53 kB<br>  ├ chunks/517-f1afbcbc9008f9bf.js       50.5 kB<br>  └ other shared chunks (total)          1.94 kB<br><br><br>○  (Static)  prerendered as static content<br>●  (SSG)     prerendered as static HTML (uses generateStaticParams)</pre><p>會發現是顯示SSG。</p><p>將建立好的檔案佈署到Azure Static Web App</p><pre>swa deploy &quot;your token&quot; --env production</pre><p>成功會顯示:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*8e4PCxMtBBX-J370VJSvLg.png" /></figure><h4>9.本機Run或是在Azure Static Web App 中測試</h4><p><a href="http://localhost:3000/API?id=6">http://localhost:3000/API?id=6</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*VyDF-agVXmepOHuPQl6n5Q.png" /></figure><p><a href="http://localhost:3000/API/6">http://localhost:3000/API/6</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*tr5vVI2eh938TVWuV1ButA.png" /></figure><h4>範例專案參照:</h4><p><a href="https://github.com/YozoraRoy/NextjsSSGToAzureStaticWebApp">GitHub - YozoraRoy/NextjsSSGToAzureStaticWebApp</a></p><p>如果覺得文章不錯或對你有幫助，請幫我多拍幾個手<br>這是一個簡單的設定，可能過程中有誤或者不清楚，有其他問題<br>也歡迎留言或傳訊息給我 : )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76478fb79665" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[關於做一個簡單的Google Web登入驗證]]></title>
            <link>https://medium.com/@yozora.sc/%E9%97%9C%E6%96%BC%E5%81%9A%E4%B8%80%E5%80%8B%E7%B0%A1%E5%96%AE%E7%9A%84google-web%E7%99%BB%E5%85%A5%E9%A9%97%E8%AD%89-93ae2553028c?source=rss-ede81e7df972------2</link>
            <guid isPermaLink="false">https://medium.com/p/93ae2553028c</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[login]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[example]]></category>
            <dc:creator><![CDATA[Roy Tsai]]></dc:creator>
            <pubDate>Thu, 26 Oct 2023 01:50:56 GMT</pubDate>
            <atom:updated>2025-02-03T16:08:09.607Z</atom:updated>
            <content:encoded><![CDATA[<p>雖然所有的教學都在Google Document。</p><p>Bard和Chatgpt都會回傳各種神奇程式碼和Cross-Origin-Opener-Policy的錯誤，寫這篇做個紀錄。</p><p><a href="https://developers.google.com/identity/gsi/web/guides/overview?hl=zh-tw">總覽 | Authentication | Google for Developers</a></p><h3>目標:</h3><ol><li>做一個登入頁面，判斷是否登入</li><li>如果登入就去下一頁</li><li>如果沒登入，就執行Oath2.0將使用者資料寫到Cookie</li><li>跳到下一頁</li><li>登出</li></ol><h3>步驟:</h3><p>到 Google Cloud 新增一個專案（或用現有的專案）</p><p>到左邊畫面得憑證，申請一個 OAuth 2.0 用戶端 ID</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MRc5OjkCqAJWZzg2IN65xg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*miX2gJIRftaTXRwQ43KqJA.png" /></figure><p>記得輸入<strong>開放登入的網域</strong>，自己測試的和線上的 (下圖第二個黃框)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D-VdU8HgxyhlaxzeDmItxw.png" /></figure><p>左邊第四欄同意畫面的部分，如果選擇了測試模式，就只有測試使用者才能用，記得把自己的或者要測試的使用者Email加入。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qElqUYdE8DnAxEVgSdMKkg.png" /></figure><p>務必填寫已授權的來源。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*mA24KeTwAtCjC0Ih-Oe8jQ.png" /></figure><p>新增並且儲存之後就會拿到 client ID</p><p>Google有提供工具可以產生程式碼，算是蠻不錯的。</p><p><a href="https://developers.google.com/identity/gsi/web/tools/configurator?hl=zh-tw">產生 HTML 程式碼 | Authentication | Google for Developers</a></p><p>填入用戶端ID(client ID)和回傳函式(callback)之後，再選擇你要的登入方式，取得程式碼。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*64uLMg9G-ZY-1Fdh9RrTyA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*6JXvRZqWmO33szE-VLMgPQ.png" /></figure><h4>參數參考:</h4><p><a href="https://developers.google.com/identity/gsi/web/reference/html-reference?hl=zh-tw#element_with_id_g_id_onload">「使用 Google HTML 登入」API 參考資料 | Authentication | Google for Developers</a></p><p>執行的時候會遇到這兩個錯誤，目前不影響流程，這邊就先無視。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*UHNaimQxGRRVIkO4AwImQg.png" /><figcaption>如果使用FedCM就不會有</figcaption></figure><h4>另外關於FedCM</h4><p>大致上就是要取代第三方(iframe、重定向和 cookie)所產生的問題，一個Federated Credential Management API(聯合憑證管理 API，簡稱FedCM)<a href="https://developer.chrome.com/en/docs/privacy-sandbox/fedcm/"><br>https://developer.chrome.com/en/docs/privacy-sandbox/fedcm/</a></p><p>但是我想要使用<strong>Bootsrap</strong>，所以HTML的程式碼就只有這樣。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*sAi18sryG6HcxwXvVdaUIA.png" /></figure><h4>登入成功之後</h4><p>把要的資料儲存在Cookie，記得<strong>自行設定</strong>使用範圍和samesite</p><h4>登出</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*goKnB85Cxy8GHp1LJngWqQ.png" /></figure><p>則是使用，google.accounts.id.disableAutoSelect();同時也會記得把外觀的按鈕改成不顯示。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*Z3n8fqvGvqgRGW3DPfEfOw.png" /></figure><p>參考:<br><a href="https://developers.google.com/identity/gsi/web/guides/automatic-sign-in-sign-out?hl=zh-tw">https://developers.google.com/identity/gsi/web/guides/automatic-sign-in-sign-out?hl=zh-tw</a></p><h4>完整Javascript範例程式碼如下:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b61fcb675770530526932baacb1c73f/href">https://medium.com/media/4b61fcb675770530526932baacb1c73f/href</a></iframe><p>如果覺得文章不錯或對你有幫助，請幫我多拍幾個手<br>這是一個簡單的設定，可能過程中有誤或者不清楚，有其他問題<br>也歡迎留言或傳訊息給我 : )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93ae2553028c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>