How to Obtain an OAuth Token to Display Google Drive Picker Using Pipedream SDK and API?

This topic was automatically generated from Slack. You can find the original thread here.

Hey Guys, I need help in one thing that when i connect to google drive using pipedream then i want to show a google drive picker to show his folders and files. Now to show the google drive picker i need OAuth Token but i am not able to get the google drive token from the sdk and api.

Need your help

How are you trying to get the OAuth token from the sdk/api?

I tried getting the OAuth Token from the API and SDK but i think they dont support giving us the token.
Can you help me in this?
from my frontend i am connecting to google drive after that i want to open a google drive picker for that user.
But i can’t do it without the OAuth Google Drive token.

Can you share the code you’re using?

Without any sensitive info

And are you in the Connect plan?

This feature requires the Connect plan, though you can test anything in the development environment in any plan

yeah im using dev env and i using free plan as of now.
i am able to connect to google drive but i want to get that Oauth token from pipedream so i can open the picker

“use client”;
import { Button } from “@/components/ui/button”;
import { createFrontendClient } from “@pipedream/sdk/browser”;
import { useEffect, useState } from “react”;

const external_user_id = “65900b51f516229bb1a84de4”;

export default function PipedreamPage() {
const [token, setToken] = useState<string | null>(null);

useEffect(() => {
async function fetchToken() {
const res = await fetch(“/api/pd”, {
method: “POST”,
body: JSON.stringify({ external_user_id }),
headers: {
“Content-Type”: “application/json”,
},
});

  console.log("res =>", res);
  if (res.ok) {
    const { token } = await res.json();
    console.log("token =>", token);
    setToken(token);
  } else {
    console.error("Failed to fetch token");
  }
}

fetchToken();

}, );

const pd = createFrontendClient({
externalUserId: external_user_id,
});

console.log(“pd ===>”, pd);

function connectAccount() {
if (!token) return;

pd.connectAccount({
  app: "google_drive",
  // oauthAppId: process.env.NEXT_PUBLIC_API_KEY, // replace or remove this
  token,
  onSuccess: (data) => {
    debugger;
    console.log(":white_check_mark: Full onSuccess data:", data);
    const { id: accountId } = data;
    console.log(`Account successfully connected: ${accountId}`);
  },
});

}

return (


Connect your account


);
}

Thanks, what is the response you’re getting?

Just to confirm, are you using a custom OAuth client?

Or Pipedream’s client? (it won’t work)

I am using pipedream’s client. Can you suggest me a better way to do it?
How can i fit the custom OAuth client fit with pipedream approach.

Yeah check this docs: OAuth Clients — Pipedream

You’ll have to create a custom OAuth client and use it in order to retrieve the tokens

Thanks for sharing this. I really appreciate this.
using the above method Will i get the Oauth token of my connected apps (google drive) and using that token i can open the picker? right? (just wanted to confirm)

Yeah I’m not sure if you’d have to implement the account selector, but yes you could by handling the account information

Using the email address or something

Not the token itself

I didn’t get what you said right now.
I use case is simple.
connect to google drive
get the OAuth token from pipedream (<- this is where i am stuck)
open the google drive picker to show files and folders of that drive.
simple

Yes you should be able to