Facebook's GraphRequestManager() undefined, but should be working? - javascript

Facebook authentication works great, but when I go to make a Graph request:
const infoRequest = new GraphRequest(
'/me',
{
accessToken: tokenString,
fields: 'email,first_name,name,last_name,picture'
},
this._responseInfoCallback
);
new GraphRequestManager().addRequest(infoRequest).start();
}
I get "TypeError: Cannot read property 'start' of undefined"
Using the Chrome debugger, everything appears like it should be working, and even storing GraphRequestManager as a variable has everything it needs until I call start(). Even using sample code I've found on this site fails when I call start(). Am I missing something obvious?
Here's a little more info. I'm importing with this:
const FBSDK = require('react-native-fbsdk');
const {
GraphRequest,
GraphRequestManager
} = FBSDK;
If I use FBGraphRequest and FBGraphRequestManager instead of above, I get errors stating that GraphReqest, etc aren't functions when I use them. Otherwise, the rest of my code looks very similar to Shivam's, but I get 'Cannot read property 'start' of undefined', so obviously the GraphRequestManager call is failing or isn't defined (which makes no sense to me).

In my experience, the fields you wish to request are specified inside parameters:
AccessToken.getCurrentAccessToken().then(
(data) => {
let accessToken = data.accessToken
const infoRequest = new GraphRequest(
'/me',{
accessToken: accessToken.toString(),
parameters: {
fields: {
string: 'email,first_name,name,last_name,picture'
}
}
},
this._responseInfoCallback.bind(this),
);
new GraphRequestManager().addRequest(infoRequest).start();
})
Ps where did you place the functions? Are they inside the class?

Related

How to get correct method scope using Google signin with angular project

I am 95% of the way to getting google signin to work. Trying to figure out 2 problems with the code. Here is my current code (simplified)
loginWithGoogle(): void {
//this one works
google.accounts.id.initialize({
client_id: 'appid.apps.googleusercontent.com',
callback: this.handleCredentialResponse
});
google.accounts.id.prompt();
}
handleCredentialResponse(response: any) {
//makes it here
this.processLogin(response);
}
processLogin(response: any) {
//doesn't make it here
}
Problem #1: When google.accounts.id.initialize fails, I can see the error on the console log, but how do I get that error in my code? I feel like I need some kind of error callback, but none is shown in the documentation. Is there now way to get that error message?
Problem #2: callback works great getting me to handleCredentialResponse, but then the "this" is no longer in the correct scope, so it cannot make it to the next method. How can I structure this to maintain the correct angular scope?
getting : TypeError: this.authorizedLogin is not a function. error.
I was able to get this to work by using ngZone:
google.accounts.id.initialize({
client_id: "appId.apps.googleusercontent.com",
callback: (window as any)['handleCredentialResponse'] =
(response: any) => this.ngZone.run(() => {
this.handleCredentialResponse(response);
})
});
google.accounts.id.prompt();
As for the error message, it appears there is no solution and likely google simply forgot to provide an error callback method.

null is not an object (evaluating 'RCTAsyncStorage.multiMerge')

I recently upgraded to Expo SDK 43.
I am now getting this error:
The line of code throwing it is:
if (!RCTAsyncStorage.multiMerge) {
I am on the latest version of AsyncStorage.
This seems to be due to my usage of firebase-js-sdk.
Unfortunately as this is an iOS/Android/Web project, it's necessary.
When I mock my Firebase exports, everything works:
const auth = () => {};
const analytics = () => {};
export default { auth, analytics };
But when I use the firebase-js-sdk functions, I get the above message.
This code causes an error (whichever version of auth I use)
let auth = initializeAuth(config, {
persistence: getReactNativePersistence(AsyncStorage),
});
//let auth = getAuth(config);
let analytics = getAnalytics(config);
export default { auth, analytics };
You could avoid that specific error by adding optional chaining (the question mark '?'):
if (!RCTAsyncStorage?.multiMerge) {
It will shortcircuit to undefined (thus making the if false) instead of throwing error from trying to check in the null object.
As to why RCTAsyncStorage would be null, you would have to check where you first get/declare it, and traceback to the point it didn't load, maybe you are using something conflicting from firebase-js-sdk.
Also multiMerge might not be supported always as mentioned in the docs:
multiMerge
[...] NOTE: This is not supported by all native implementations.

Getting a new id for a firestore doc to add it to the document itself

According to the documentation here, it should be possible get an id for a not-yet-created firestore document, add it the object to be saved, and then persist it like this:
// Add a new document with a generated id.
var newCityRef = db.collection("cities").doc();
// later...
newCityRef.set(data);
In my application, I follow this pattern with the following code:
async createNewProject(projectObject : Project) : Promise<boolean> {
let doc = this.firestore.collection("projects").doc();
projectObject.id = doc.ref.id;
try {
await doc.set(projectObject);
} catch(err) {
console.error(err);
return false;
}
return true;
}
When it runs though, i get an error in the console:
FirebaseError: Function CollectionReference.doc() requires its first argument to be of type non-empty string, but it was: undefined
Can anybody shed any light? I've seen other folks on her referencing this method (using the doc method with no parameters as the solution to the problem, yet others are seeing this error. Is this some kind of API on the Angular implementation of the API, or a problem at the firebase side of things (or did I do something wrong?)
The doc() method returns a DocumentReference, which does not have a ref property but has an id one. Therefore you need to do:
projectObject.id = doc.id;
instead of
projectObject.id = doc.ref.id;

Empty object after `require`

I'm trying to use your relaxed-json in my Electron app. Here is a simple code, GetDeviceList() is triggered on a button-push action:
const driver = require('meteor_driver').MeteorConnection.MeteorConnection;
const relaxed = require('relaxed-json');
const connection = new driver();
function GetDeviceList() {
console.log(connection.port);
console.log("Launching");
console.log(relaxed);
relaxed.transform('[{id:0,},{id:1,},{id:2,},]');
}
The console.log show me an empty object. And I got an error message Uncaught TypeError: relaxed.transform is not a function.
Otherwise, the package works properly when it's not used with electron.
Note that I don't encounter any require-related issue, so the modules must be valid isn't ?

How can I solve "Cannot call method "addL" of undefined"

I was trying to make by myself a "library" for my personal project which uses local storage for nearly everything and I got this error.
The Browser I am using is Google Chrome on the last version. It says no error line on the console and the error is:
TypeError: Cannot call method 'addL' of undefined.
JavaScript
function local (title) {
var storeTitle = title;
this.addL = function(lString) {
var storeText = lString;
localStorage.setItem(storeTitle, storeText);
};
this.removeL = function() {
localStorage.removeItem(storeTitle);
};
this.getL = function () {
localStorage.getItem(storeTitle);
};
};
I can't find the error and when I google Cannot call method ... of undefined it shows a lot of pages but with different content, not the one I'm looking for. I found from Google Maps API to jQuery API.
I learned this "way" from another question here StackOverflow.
You are missing the new keyword. So try this:
new local("locally").addL("stored")

Categories

Resources