-
-
Notifications
You must be signed in to change notification settings - Fork 119
[@nativescript/google-signin] Google Sign In v2.1.1 error in Nativescript (Core/Plain) v8.9.1 #630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think this may be due to your example calling googlesignin.mov |
Am using bluestack for emulator, & Andoid Pie, does it matter? And what's wrong about my configure? Btw, the above error appears before the page containing the sign-in button is displayed. |
Full Codelogin.jsimport { Application } from "@nativescript/core";
import { login as googleLogin } from "~/google";
import { GlobalModel } from "~/global_model";
var context = new GlobalModel([{ page: "Backup-restore" }]);
export function onLoaded() {
// loadMyAdMob();
}
export function onNavigatingTo(args) {
const page = args.object;
page.bindingContext = context;
}
export function onDrawerButtonTap(args) {
const sideDrawer = Application.getRootView();
sideDrawer.showDrawer();
}
export function handleSignIn() {
googleLogin()
.then(({ userInfo }) => {
console.log("Login sukses!", userInfo);
})
.catch((err) => {
console.error("Login gagal:", err);
});
} login.xml<Page
loaded="onLoaded"
navigatingTo="onNavigatingTo"
xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:ui="@nativescript/google-signin">
<ActionBar flat="true">
<NavigationButton visibility="hidden"></NavigationButton>
<GridLayout columns="50, auto, *, auto, 5, auto, 10">
<Label class="fas" text="" tap="onDrawerButtonTap" col="0" />
<Label class="action-bar-title ubuntu-bold" text="Backup & Restore" tap="onDrawerButtonTap" col="1"/>
</GridLayout>
</ActionBar>
<GridLayout rows="auto, 10, *, 10">
<ScrollView row="0">
<StackLayout margin="10 0">
<ui:GoogleSigninButton tap="handleSignIn" colorScheme='auto' colorStyle='standard'/>
</StackLayout>
</ScrollView>
</GridLayout>
</Page>
Helper google.jsimport { knownFolders, Http } from "@nativescript/core";
import { GoogleSignin } from "@nativescript/google-signin";
export async function login() {
await GoogleSignin.configure({
scopes: ["https://www.googleapis.com/auth/drive.file"],
webClientId:
"12345-xxxxxxxxx.apps.googleusercontent.com",
offlineAccess: true,
});
const userInfo = await GoogleSignin.signIn();
const tokens = await GoogleSignin.getTokens();
return {
userInfo,
accessToken: tokens.accessToken,
};
}
export async function logout() {
await GoogleSignin.signOut();
}
export async function uploadToDrive(accessToken, localPath, remoteName) {
const file = knownFolders.documents().getFile(localPath);
const content = file.readSync((err) => {
if (err) throw err;
});
const metadata = {
name: remoteName,
mimeType: "application/x-sqlite3",
};
const boundary = "-------314159265358979323846";
const delimiter = `\r\n--${boundary}\r\n`;
const closeDelimiter = `\r\n--${boundary}--`;
const body =
delimiter +
"Content-Type: application/json\r\n\r\n" +
JSON.stringify(metadata) +
delimiter +
"Content-Type: application/x-sqlite3\r\n\r\n" +
content +
closeDelimiter;
const response = await Http.request({
url: "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": `multipart/related; boundary=${boundary}`,
},
content: body,
});
return response;
}
export async function downloadFromDrive(fileId, accessToken, saveAsFilename) {
const response = await Http.request({
url: `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`,
method: "GET",
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
const file = knownFolders.documents().getFile(saveAsFilename);
file.writeSync(response.content.toUint8Array());
return file.path;
} |
Info
Code
Error
Exception
Logcat
The text was updated successfully, but these errors were encountered: