I pick an image using ImagePicker from 'expo-image-picker'. Said image is stored in base64Ref
If I send the file to Google Drive using b64 = false the upload works fine.
If I use b64 = true the file is never sent. All The info I can get is:
response
{
"type": "default",
"status": 400,
"ok": false,
"statusText": "",
"headers": {
"map": {
"content-type": "text/plain; charset=utf-8",
"date": "Tue, 21 Dec 2021 20:03:22 GMT",
"server": "UploadServer",
"alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
"content-length": "25",
"x-guploader-uploadid": "ADPycdsJHDbYYbvBnEgBfKrSEN6vSN2MswfCUxxJeSc6CFmQZpeWx43budeb9Fumt-bWmja5j3mjGNwAfDEn4bosjcQ"
}
},
"url": "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",
"bodyUsed": false,
"_bodyInit": {
"_data": {
"size": 25,
"offset": 0,
"blobId": "d811ac9c-431d-4582-8de4-d31adb93ca8f",
"__collector": {}
}
},
"_bodyBlob": {
"_data": {
"size": 25,
"offset": 0,
"blobId": "d811ac9c-431d-4582-8de4-d31adb93ca8f",
"__collector": {}
}
}
This is the code
const b64 = false;
Drive.files.createFileMultipart(
"data:image/png;base64,"+base64Ref.current,
"image/png", {
parents: ["root"],
name: "MyImage.png"
},
b64)
.then((response) => {
let q = response;
console.log("response");
console.log(JSON.stringify(q));
})
Related
I can't get notifications when smoke detected. What is wrong here? Is there a github example?
Followed:
https://developers.google.com/assistant/smarthome/develop/notifications#proactive-notification-payload
Voice notifications are "on" in my phone.
..
Notification request function works under exports.reportstate:
var randomrequestId = (Math.floor(1000000000 + Math.random() * 9000000000) * 123).toString();
var randomeventId = (Math.floor(1000000000 + Math.random() * 9000000000) * 11).toString();
const res = await homegraphClient.devices.reportStateAndNotification({
requestBody: {
agentUserId: kullanici,
eventId: randomeventId,
requestId: randomrequestId,
payload: {
devices: {
notifications: {
[deviceId]: {
SensorState: {
priority: 0,
name: "SmokeLevel",
currentSensorState: "smoke detected",
}
}
}
}
}
}
});
I can see changes in home graph viewer, works as expected..
homegraph1
and
homegraph2-smoke detected
..
This is the response from cloud function logs
{
"config": {
"url": "https://homegraph.googleapis.com/v1/devices:reportStateAndNotification",
"method": "POST",
"userAgentDirectives": [
{
"product": "google-api-nodejs-client",
"version": "4.4.3",
"comment": "gzip"
}
],
"data": {
"requestId": "1202169683718",
"eventId": "35996036483",
"agentUserId": "dafdafdfadaf#gmail-com",
"payload": {
"devices": {
"notifications": {
"484BA8-1": {
"SensorState": {
"priority": 0,
"name": "SmokeLevel",
"currentSensorState": "smoke detected"
}
}
}
}
}
},
"headers": {
"x-goog-api-client": "gdcl/4.4.3 gl-node/10.24.1 auth/6.1.3",
"Accept-Encoding": "gzip",
"User-Agent": "google-api-nodejs-client/4.4.3 (gzip)",
"Authorization": "Bearer ya29.c.b0AXv0zTMEKY7pLs6MVA_PPM4Ax9U-zvQB6klzF98HZyZXUfdahbvJk5nXScEbBh95H9RD_4tsqskXeiYDK7wtpkUHzuLgnFKr2bwn3l-MEQVMY_l-Sd4awUOy75SQ1imXRURwxcrhagKael0ZtACVYValnRzQe-Ue16xDBN4JVawMPQOvfVRE3RZmNVxPi2_QZYtsy8Tq0wH3SJ8-gLfn9IHoocWKvYPF0G02DFouOlbMuYNa7oOYQEzNa5Ni62p__spJUXCnvlEplUxrVi8WbAVw8WTL0ny0lMyxZLmmzIeU....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................",
"Content-Type": "application/json",
"Accept": "application/json"
},
"params": {},
"retry": true,
"body": "{\"requestId\":\"1202169683718\",\"eventId\":\"35996036483\",\"agentUserId\":\"dafdafdfadaf#gmail-com\",\"payload\":{\"devices\":{\"notifications\":{\"484BA8-1\":{\"SensorState\":{\"priority\":0,\"name\":\"SmokeLevel\",\"currentSensorState\":\"smoke detected\"}}}}}}",
"responseType": "json"
},
"data": {
"requestId": "1202169683718"
},
"headers": {
"alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
"cache-control": "private",
"connection": "close",
"content-encoding": "gzip",
"content-type": "application/json; charset=UTF-8",
"date": "Wed, 06 Jul 2022 07:46:35 GMT",
"server": "ESF",
"transfer-encoding": "chunked",
"vary": "Origin, X-Origin, Referer",
"x-content-type-options": "nosniff",
"x-frame-options": "SAMEORIGIN",
"x-xss-protection": "0"
},
"status": 200,
"statusText": "OK",
"request": {
"responseURL": "https://homegraph.googleapis.com/v1/devices:reportStateAndNotification"
}
}
Data in fb:
attributes, currentsensordata ...
With Strapi v3 my code perfectly working:
api.loadSource(async actions => {
const { data } = await axios.get('http://localhost:1337/events')
const collection = actions.addCollection({
typeName: 'Event',
path: '/events/:id'
})
for (const event of data) {
collection.addNode({
id: event.id,
})
}
})
But with update to Strapi v4 I'm getting the error: TypeError: gridsome.server.js: data is not iterable (29:25)
27 | })
28 |
> 29 | for (const event of data) {
| ^
30 | collection.addNode({
31 | id: event.id,
I know, that now Strapi added /api/ to the path and also not showing relations by default. But this not fixing the situation:
const { data } = await axios.get('http://localhost:1337/api/events?populate=')
output when enter in browser http://localhost:1337/api/events/1
{
"data": {
"id": 1,
"attributes": {
"title": "Coffe",
"description": "We get together",
"date": "2022-05-30T22:00:00.000Z",
"duration": 2,
"price": 0,
"createdAt": "2022-06-11T12:40:06.542Z",
"updatedAt": "2022-06-11T19:45:53.548Z",
"publishedAt": "2022-06-11T13:05:10.375Z"
}
},
"meta": {
}
}
When enter http://localhost:1337/api/events/1?populate=*
{
"data": {
"id": 1,
"attributes": {
"title": "Coffe",
"description": "We get together",
"date": "2022-05-30T22:00:00.000Z",
"duration": 2,
"price": 0,
"createdAt": "2022-06-11T12:40:06.542Z",
"updatedAt": "2022-06-11T19:45:53.548Z",
"publishedAt": "2022-06-11T13:05:10.375Z",
"categories": {
"data": [
{
"id": 1,
"attributes": {
"name": "Music",
"createdAt": "2022-06-11T12:44:07.472Z",
"updatedAt": "2022-06-11T12:45:32.721Z",
"publishedAt": "2022-06-11T12:45:32.720Z"
}
}
]
}
}
},
"meta": {
}
}
I want to make a custom scheme with local strategies but I don't know how can I do it using customScheme. Documentation of nuxt/auth v5 doest not help me
I want to execute two endpoint:
1st- request
POST /oauth/v2/token
HEAD:
Content-Type: application/x-www-form-urlencoded
body of the request:
clientId : string
clientSecret: string
grantType: string
username: string
password: string
response:
{
"accessToken": "string",
"expireTime": "2022-01-10T20:29:10.721Z",
"refreshToken": "string"
}
2nd- request
GET /security/users/me
HEAD
x-locale: fr|en
authorization: Bearer <TOKEN>
response:
{
"username": "string",
"firstname": "string",
"lastname": "string",
"email": "string",
"phone": "string",
"locale": "fr",
"id": 1,
"enabled": true,
"createdAt": "2022-01-10T20:38:36.478Z",
"updatedAt": "2022-01-10T20:38:36.478Z",
"expiresAt": "2022-01-10T20:38:36.478Z",
"loggedAt": "2022-01-10T20:38:36.478Z",
"roles": [
{
"name": "string",
"description": "string",
"code": "string",
"id": 1,
"enabled": true,
"createdAt": "2022-01-10T20:38:36.478Z",
"updatedAt": "2022-01-10T20:38:36.478Z",
"translations": {
"fr": {
"name": "string",
"description": "string"
},
"en": {
"name": "string",
"description": "string"
}
},
"permissions": [
{
"id": 1,
"code": "string",
"endUI": {
"name": "string",
"title": "string",
"id": 1,
"code": "string",
"type": {
"name": "string",
"code": "string",
"id": 1,
"enabled": true,
"createdAt": "2022-01-10T20:38:36.478Z",
"updatedAt": "2022-01-10T20:38:36.478Z",
"translations": {
"fr": {
"name": "string"
},
"en": {
"name": "string"
}
}
},
"module": {
"name": "string",
"description": "string",
"code": "string",
"id": 1,
"enabled": true,
"createdAt": "2022-01-10T20:38:36.478Z",
"updatedAt": "2022-01-10T20:38:36.478Z",
"translations": {
"fr": {
"name": "string",
"description": "string"
},
"en": {
"name": "string",
"description": "string"
}
}
},
"icon": "string",
"uri": "string",
"translations": {
"fr": {
"name": "string",
"title": "string"
},
"en": {
"name": "string",
"title": "string"
}
}
}
}
]
}
],
"avatar": {
"id": 1,
"url": "string"
}
}
nuxt.config.js
modules: [
// https://go.nuxtjs.dev/axios
'#nuxtjs/axios',
// https://go.nuxtjs.dev/pwa
'#nuxtjs/pwa',
'#nuxtjs/auth-next',
'#nuxtjs/dotenv',
'#nuxtjs/i18n', [
'nuxt-vuex-localstorage',
{
mode: 'debug',
localStorage: [
'user',
'service',
'location',
'storeType',
'warehouse',
'openingRange',
'store',
'holiday',
'taxon',
'provider',
'productOption',
'productAttribute',
'product',
'productVariant',
'glassesCatalog'
],
},
],
],
router: {
middleware: ['auth']
},
// Auth Strategies
auth: {
strategies: {
customStrategy: {
_scheme: '~/schemes/customScheme',
endpoints: {
login: {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
url: '/oauth/v2/token',
method: 'post'
},
user: {
url: '/security/users/me',
method: 'get',
propertyName: '',
headers: {
'x-locale': 'fr',
'Authorization': `Bearer ${It should be a token (accessToken) for the first request}`
}
}
}
}
}
}
~/schemes/customeScheme.js
import { LocalScheme } from '~auth/runtime'
export default class CustomScheme extends LocalScheme {
// Override `fetchUser` method of `local` scheme
async fetchUser (endpoint) {
// Token is required but not available
if (!this.check().valid) {
return
}
// User endpoint is disabled.
if (!this.options.endpoints.user) {
this.$auth.setUser({})
return
}
// Try to fetch user and then set
return this.$auth.requestWith(
this.name,
endpoint,
this.options.endpoints.user
).then((response) => {
const user = getProp(response.data, this.options.user.property)
// Transform the user object
const customUser = {
...user,
fullName: user.firstName + ' ' + user.lastName,
roles: ['user']
}
// Set the custom user
// The `customUser` object will be accessible through `this.$auth.user`
// Like `this.$auth.user.fullName` or `this.$auth.user.roles`
this.$auth.setUser(customUser)
return response
}).catch((error) => {
this.$auth.callOnError(error, { method: 'fetchUser' })
})
}
}
~/login.vue
onSubmit(){
this.isSubmitting = true;
this.isDisabled= true;
let formData = new FormData();
formData.append("clientId", process.env.CLIENT_ID);
formData.append("clientSecret", process.env.CLIENT_SECRET);
formData.append("grantType", "password");
formData.append("username", this.dataUser.username);
formData.append("password", this.dataUser.password);
this.$refs.dataUser.validate(async (valid, fieldsError) => {
this.validate = valid;
if(valid){
try {
let response = await this.$auth.loginWith('customStrategy', { data: formData })
console.log(response);
this.$store.dispatch('storeSecurity/storeUserToken', response.data);
} catch (error) {
this.$message.error({content: this.$t("login.error"), key, duration: 3});
}
}
});
},
If I want to fetch user, how can i do please ???
everything I do gives me errors that have no answers in the doc
I need help please
You should use $auth.setUser(user) to set the current user after successfully login. That is iif your endpoints.user doesn't work.
I am trying to add sign-in functionality to my react-native application. I have implemented google auth through AppAuth to obtain an access token and now I want to obtain the user's email
I have tried different URLs but all of them return gibberish. I have created a project for my app in google and have enabled the People API and done all the credential settings
_handlePressAsync = async () => {
config = {
issuer: 'https://accounts.google.com',
clientId: GOOGLE_APP_ID,
scopes: ['profile','email'],
}
let result = await AppAuth.authAsync(config);
this.setState({ result });
console.debug(result);
//let userInfo = await fetch('https://people.googleapis.com/v1/people/me', {headers: { Authorization: `Bearer ${result.accessToken}` }});
//let userInfo = await fetch(`https://www.googleapis.com/oauth2/v3/userinfo?access_token=${result.accessToken}`);
console.debug('-------------USER INFO-------------')
console.debug(userInfo);
};
There are 2 let userInfo = ... lines, I tried them one at a time.
The first one returns:
Response {
"_bodyBlob": Blob {
"_data": Object {
"blobId": "ca99a1a3-8a69-443e-aa41-6d0507e1d0e0",
"offset": 0,
"size": 251,
},
},
"_bodyInit": Blob {
"_data": Object {
"blobId": "ca99a1a3-8a69-443e-aa41-6d0507e1d0e0",
"offset": 0,
"size": 251,
},
},
"headers": Headers {
"map": Object {
"alt-svc": "quic=\":443\"; ma=2592000; v=\"46,43,39\"",
"cache-control": "public, max-age=0",
"content-type": "application/json; charset=UTF-8",
"date": "Sun, 08 Sep 2019 06:00:36 GMT",
"server": "ESF",
"vary": "Referer",
"x-content-type-options": "nosniff",
"x-frame-options": "SAMEORIGIN",
"x-xss-protection": "0",
},
},
"ok": false,
"status": 400,
"statusText": undefined,
"type": "default",
"url": "https://people.googleapis.com/v1/people/me",
}
while the second one returns:
Response {
"_bodyBlob": Blob {
"_data": Object {
"blobId": "318cb3ab-ae66-48d7-a5f2-302cd0d25278",
"offset": 0,
"size": 323,
},
},
"_bodyInit": Blob {
"_data": Object {
"blobId": "318cb3ab-ae66-48d7-a5f2-302cd0d25278",
"offset": 0,
"size": 323,
},
},
"headers": Headers {
"map": Object {
"alt-svc": "quic=\":443\"; ma=2592000; v=\"46,43,39\"",
"cache-control": "public, max-age=0",
"content-type": "application/json; charset=utf-8",
"date": "Sun, 08 Sep 2019 06:04:53 GMT",
"expires": "Mon, 01 Jan 1990 00:00:00 GMT",
"server": "ESF",
"vary": "Referer",
"x-content-type-options": "nosniff",
"x-frame-options": "SAMEORIGIN",
"x-xss-protection": "0",
},
},
"ok": true,
"status": 200,
"statusText": undefined,
"type": "default",
"url": "https://www.googleapis.com/oauth2/v3/userinfo?access_token=ya29.Glt9B43nkzGHkWAcTmplkcO2geSFHI8cxSBVvnDwCbbSUPnM79Xx7zxwOw8CzhhGZfxmGS9mEKCzjPVeRFj3hruTMinkkjkh6PqhCvr-Hy9sQtJEEAxSkgwrkjTY",
}
I'm using GraphQL.Net and getting the following when trying to use the API.
{
"version": {
"major": 1,
"minor": 1,
"build": -1,
"revision": -1,
"majorRevision": -1,
"minorRevision": -1
},
"content": {
"headers": [
{
"key": "Content-Type",
"value": [
"application\/json; charset=utf-8"
]
}
]
},
"statusCode": 400,
"reasonPhrase": "Bad Request",
"headers": [
],
"requestMessage": {
"version": {
"major": 2,
"minor": 0,
"build": -1,
"revision": -1,
"majorRevision": -1,
"minorRevision": -1
},
"content": null,
"method": {
"method": "GET"
},
"requestUri": null,
"headers": [
],
"properties": {
}
},
"isSuccessStatusCode": false
}
It is quite vague as to what the cause of the error is. Is there something wrong with the setup of my queries / types? Or is it in my request? Is it about authentication?
I'm not sure which code to share, so I uploaded my API library at: https://github.com/jonasarcangel/GraphQLIssue
Request payload is as follows (using Apollo Angular):
{
"operationName": "configsQuery",
"variables": {
"id": "",
"module": "admin\/configs",
"name": "canActivate"
},
"query": "query configsQuery($id: String, $module: String, $name: String) {\n configs(id: $id, module: $module, name: $name) {\n id\n createdBy\n createdDate\n updatedBy\n updatedDate\n name\n module\n value\n __typename\n }\n}\n"
}