Skip to content
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

Error with FacebookSdk Initialize [SOLUTION: read v8 release notes: need client access token configured now] #236

Closed
boreales opened this issue Apr 27, 2022 · 44 comments

Comments

@boreales
Copy link

🐛 Bug Report

I keep having the error : The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.

To Reproduce

Install the package
Fill the AndroidManifest and strings.xml files with facebook-app-id as in the docs.
Run npx react-native run-android or launch the app through Android Studio on the emulator.

I also tried with a brand new app and another computer. I still have the same issue.

Expected Behavior

The SDK should be auto-initialized at the launch of the app.

Code Example

Environment

System:
    OS: Windows 10 10.0.22000
    CPU: (12) x64 Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
    Memory: 1.93 GB / 15.92 GB
  Binaries:
    Node: 16.14.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.5.5 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: Version     2021.1.0.0 AI-211.7628.21.2111.8309675
    Visual Studio: Not Found
  Languages:
    Java: 17.0.2 - C:\Program Files\Common Files\Oracle\Java\javapath\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.67.4 => 0.67.4 
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
@matin91
Copy link

matin91 commented Apr 27, 2022

Same here

@mikehardy
Copy link
Collaborator

I also tried with a brand new app and another computer. I still have the same issue.

Our example app is literally built by a script, fully automated

Check it out: https://github.com/thebergamo/react-native-fbsdk-next/blob/master/refresh-example.sh

Run that, compare output to your project, you're missing a step somewhere, somehow. It's not a module problem though, and support questions are best on stackoverflow or similar until you can demonstrate a bug with steps to reproduce
https://stackoverflow.com/help/minimal-reproducible-example
https://stackoverflow.com/help/how-to-ask

@AlexandreLage
Copy link

Same here

@mikehardy
Copy link
Collaborator

Same answer 🤷 - put some effort in please

@mikehardy
Copy link
Collaborator

I'm not trying to be flippant either: I literally provide a fully automated scripted build to create an example, and last I checked (before last release), it worked. I really don't know what more I can do

@lan2k1
Copy link

lan2k1 commented Apr 28, 2022

Before my project was working properly. But I saw this issue yesterday. I can't run the project right now.

@mikehardy
Copy link
Collaborator

Providing exactly as much information as you have provided, I run my project just fine. Who is right? Neither of us without a reproduction. Behold: https://github.com/thebergamo/react-native-fbsdk-next/blob/master/refresh-example.sh a reproduction

How's it go when you run it?

@arkkosoftMiKolbi
Copy link

Hi, I have the same problem. The project was working yesterday and today it doesn't work.
My coworker has the same project and he can run it without problems.

image

@mikehardy
Copy link
Collaborator

mikehardy commented Apr 28, 2022

I just followed the README in the example, it works

clone the repo
yarn example:install
yarn example:start
yarn example:android

No reproduction, no more comments from me. You will have to dig in on your projects and determine what happened, sorry

If anyone learns anything useful please make a PR to the docs, or if there really is a bug a PR to the module and/or the example to actually demonstrate it would be great.

Statements of "it doesn't work" lack substance and do not help unfortunately. Neither does visual evidence (screenshots) of same, as I can just post a screenshot of it working and it's equally pointless

I repeat for context:

Our example app is literally built by a script, fully automated

Check it out: https://github.com/thebergamo/react-native-fbsdk-next/blob/master/refresh-example.sh

Run that, compare output to your project, you're missing a step somewhere, somehow. It's not a module problem though, and support questions are best on stackoverflow or similar until you can demonstrate a bug with steps to reproduce
https://stackoverflow.com/help/minimal-reproducible-example
https://stackoverflow.com/help/how-to-ask

@arkkosoftMiKolbi
Copy link

Thanks for your reply. 

I ran my project on iOS and it works. But when I ran my project on Android, it doesn't work.

Before reviewing the application and Facebook documentation, we found the solution.

The client token had to be added to string.xml:

<string name="facebook_client_token">56789string> 

Next add the meta-data in the application element, in the AndroidManifest.xml:

<meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>

After that, the application works again. 

@ch3tan03
Copy link

ch3tan03 commented Apr 28, 2022

Before my project was working properly. But I saw this issue yesterday. I can't run the project right now.

same for me all of a sudden I'm getting this error. above solution from @arkkosoftMiKolbi fixed my issue. thanks

@phuongwd
Copy link

We have to set the facebook_client_token to /app/manifests/AndroidManifest.xml

Screen Shot 2022-04-28 at 16 00 05

@mikehardy
Copy link
Collaborator

mikehardy commented Apr 28, 2022

Glad you found the solution!

Please pay very very careful attention to release notes on breaking change release notes, if you see a breaking change expect your app to break unless you update it somehow

https://github.com/thebergamo/react-native-fbsdk-next/releases
https://github.com/thebergamo/react-native-fbsdk-next/releases/tag/v8.0.0

Client access token required: configure on Facebook console and in the app

Also from our example script:

# Facebook App Client Token will be required with Facebook SDKs 13+
sed -i -e 's/<\/resources>/ <string name="facebook_client_token">d157902d0bff64b4c1daaf26e32852e9<\/string>\n<\/resources>/' android/app/src/main/res/values/strings.xml

@mikehardy mikehardy changed the title Error with FacebookSdk Initialize Error with FacebookSdk Initialize [SOLUTION: read v8 release notes: need client access token configured now] Apr 28, 2022
@mikehardy
Copy link
Collaborator

One other thing I'll mention: if this happened without you knowing, you should examine your dependency management. Are you depending on this module with a + dependency, so it can just update any time, and break your builds without you knowing? That is a dangerous practice because you'll end up in situations like this. Depend on this module like "react-native-fbsdk-next": "^8.0.0" in your package.json so you are bound to the major version

We do our best not to issue breaking changes without release notes indicating the exact changes required, but you have to use semantic versioning appropriately for that to work for you

@keShraa
Copy link

keShraa commented Apr 28, 2022

Hey guys,
As mentioned below, you have to add the client token to the AndroidManifest:
<meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>

I had to create a token on the Meta for Developers website.

It is now working for me ! Thanks 🙏🏻

Thanks for your reply. 

I ran my project on iOS and it works. But when I ran my project on Android, it doesn't work.

Before reviewing the application and Facebook documentation, we found the solution.

The client token had to be added to string.xml:

<string name="facebook_client_token">56789string> 

Next add the meta-data in the application element, in the AndroidManifest.xml:

<meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>

After that, the application works again.

@phuongwd
Copy link

phuongwd commented Apr 29, 2022

Glad you found the solution!

Please pay very very careful attention to release notes on breaking change release notes, if you see a breaking change expect your app to break unless you update it somehow

https://github.com/thebergamo/react-native-fbsdk-next/releases https://github.com/thebergamo/react-native-fbsdk-next/releases/tag/v8.0.0

Client access token required: configure on Facebook console and in the app

Also from our example script:

# Facebook App Client Token will be required with Facebook SDKs 13+
sed -i -e 's/<\/resources>/ <string name="facebook_client_token">d157902d0bff64b4c1daaf26e32852e9<\/string>\n<\/resources>/' android/app/src/main/res/values/strings.xml


@mikehardy thanks for detailed information.

We are still using the version ^4.6.0. It was working to 27 Apr 2022.

// yarn.lock
react-native-fbsdk-next@^4.6.0:
  version "4.6.0"
  resolved "https://registry.yarnpkg.com/react-native-fbsdk-next/-/react-native-fbsdk-next-4.6.0.tgz#0e70aa6d64e99762e6b22b1344eebae3f7fbfcb5"
  integrity sha512-FPYLUFSWf7V4i084jKpSt8tc1DLkuBm38eYdq4RwpGcojxXIciQ8qQi9DRLNAxqNZHd0G/P6edSVEGsrjtvV7w==

./gradlew :app:dependencies
Screen Shot 2022-04-29 at 10 17 41

For more information, https://github.com/facebook/facebook-android-sdk/blob/main/CHANGELOG.md#1320

Screen Shot 2022-04-29 at 10 21 20

@mikehardy
Copy link
Collaborator

mikehardy commented Apr 29, 2022

That + in the dependencies there is what let the breaking change in the underlying SDK slip through i think 🤔

[EDIT: turns out we have a 13.+ here in our dependencies, and while they indicated client access token was mandatory in 13.0 (and 13.1) they only just started actually breaking if it was missing in 13.2, which is a bit sneaky / not really semantic-release compatible. That explains why when we made no change here, it all the sudden started breaking for people on April 22 when facebook-android-sdk 13.2 was released and started coming in with that + here. We may pin the version in the future if breaks happen again...]

@smrgrg
Copy link

smrgrg commented May 3, 2022

Thanks for your reply. 

I ran my project on iOS and it works. But when I ran my project on Android, it doesn't work.

Before reviewing the application and Facebook documentation, we found the solution.

The client token had to be added to string.xml:

<string name="facebook_client_token">56789string> 

Next add the meta-data in the application element, in the AndroidManifest.xml:

<meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>

After that, the application works again.

This worked for me. Thanks.

@mikehardy
Copy link
Collaborator

See: https://github.com/facebook/facebook-android-sdk/blob/main/CHANGELOG.md#1320

The client token is now mandatory. SDK initialization will have a check on it and throw out an exception if the client token is not available.

@sspeng123
Copy link

Thanks for your reply. 

I ran my project on iOS and it works. But when I ran my project on Android, it doesn't work.

Before reviewing the application and Facebook documentation, we found the solution.

The client token had to be added to string.xml:

<string name="facebook_client_token">56789string> 

Next add the meta-data in the application element, in the AndroidManifest.xml:

<meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>

After that, the application works again.

fixed my issue. thanks

@dtthanh1
Copy link

Hey guys, I tried to integrate FB SDK with my app. Everything runs perfectly on emulator but when I push it on TestFlight my app crashed. Is anyone facing this issue like me?

@mikehardy
Copy link
Collaborator

Nope, if you ran the app on a device plugged in to your development machine and opened the log in Console.app you could post useful information to troubleshoot.

@dtthanh1
Copy link

Okay, it turns out the FBAudienceNetwork 6.10 is having a bug which made my app keep crashing. Downgraded to 6.9 and hope FB's team will release a new version to fix this bug soon. Thanks for your help tho

@mikehardy
Copy link
Collaborator

@dtthanh1 oh my! That's new information, had not heard of this yet. Do you have any links to upstream issues that people could subscribe to, or related release notes? Have you logged the issue upstream yourself or collaborated with upstream repo to characterize + fix the issue? Otherwise no one else may be aware of it

@dtthanh1
Copy link

After hours of debugging and researching on Google and I came up to this.
https://developers.facebook.com/support/bugs/659029835161893/

@mikehardy
Copy link
Collaborator

Fantastic work pushing that through to acknowledgement / "scheduled for fix in next release". Sounds like 6.11 of FBAudienceNetwork will fix it, while 6.10 is busted.

What is strange is that when I scan for that pod here in our example - https://github.com/thebergamo/react-native-fbsdk-next/blob/master/RNFBSDKExample/ios/Podfile.lock - I don't see it. Is this part of a regular facebook sdk integration or something extra? Stated differently, with the goal in mind: will this affect many of the users here or only users doing XYZ (unspecified) ? Seems like it's "only users doing XYZ" and the XYZ is ... ads? This is mostly out of curiosity but might help others' set expections.

Either way, thanks a bunch for sharing the link

@shamilovtim
Copy link

This error persists for me. I confirmed that the facebook_client_token comes through gradle just fine. However the native SDK still throws the error. It's actually somewhat concerning that a native SDK dissatisfied with a token can crash your entire application like this. I would hope they're not performing any validation on the token and crashing apps with invalid tokens. That being said, I went into the admin panel and confirmed that the token is correct, appid is correct, and so on. Stumped as to what's causing this and have tried many different solutions. Going to downgrade this SDK to before the token was ever required and hope that fixes things.

@mikehardy
Copy link
Collaborator

It's possible they will start denying API requests without them or with the old SDK, so careful with that - you might be able to just configure it directly in the AndroidManifest if you want? I think that would work? I don't think they validate it on startup but I'm sure they'll validate it when you use the API, so if you put a random string in there your app will at least boot but it won't work for API calls to facebook.

I actually prefer an SDK that fails fast. Can you imagine if they made it a requirement but then you didn't find out until you tried a non-login API or something and just got an error? Much better as you update the SDK to just have it work or not on your first test IMHO

@shamilovtim
Copy link

It's possible they will start denying API requests without them or with the old SDK, so careful with that - you might be able to just configure it directly in the AndroidManifest if you want? I think that would work? I don't think they validate it on startup but I'm sure they'll validate it when you use the API, so if you put a random string in there your app will at least boot but it won't work for API calls to facebook.

I actually prefer an SDK that fails fast. Can you imagine if they made it a requirement but then you didn't find out until you tried a non-login API or something and just got an error? Much better as you update the SDK to just have it work or not on your first test IMHO

Good point but maybe done at compile time is better?

Anyways, are they doing any validation of the token or appid right now? Could that be causing this?

@shamilovtim
Copy link

same issue. I'm not even using their API at all. downgrading doesn't work either. I've tried just about everything. How do we convince them to stop throwing from their SDK and blocking our entire app at startup? this is crazy. Screen Shot 2022-08-26 at 1 44 56 AM

@shamilovtim
Copy link

shamilovtim commented Aug 26, 2022

Welp I figured it out. One more build clean and it actually worked to put dummy values into AndroidManifest. What was happening was I had dynamic gradle values: android:value="${foo}". From everything I know these have always worked but upon upgrade this plugin started throwing when encountering those. I have now moved my dynamic keys into manifestPlaceholders and I'm referencing them using @string/facebook_app_id and @string/facebook_client_token.

@mikehardy
Copy link
Collaborator

manifestPlaceholders have always worked for me in the past, and I have not tried dynamic values as you indicate @shamilovtim - you may have found the critical reproduction, since I was not able to reproduce this.

Everyone else having this problem, does an AndroidManifest with variables seem like it's your case?

As for verification at compile time, not sure how you verify a configuration string at compile time when the config files can be so widely varied. And a crash right at startup is really just about the same, the delay is only marginally longer but the signal is just as absolute. Perhaps the error would be better ?

As for them verifying the ID, how did it go when you sent in a fake ID? I'm guessing the API calls failed. I've never tried to subvert their app auth token system by feeding it unexpected data so I can't say.

@mehraj43
Copy link

image

help me guyzz facing this issue when building

@mikehardy
Copy link
Collaborator

@mehraj43 - this is a poor question --> https://stackoverflow.com/help/how-to-ask -- also, what you displayed in a very difficult to read image (vs formatted text) is simply a warning. Not an error. You have not actually shown the error. This module currently has no compilation errors that I know of, your problem is elsewhere

@mehraj43
Copy link

@mehraj43 - this is a poor question --> https://stackoverflow.com/help/how-to-ask -- also, what you displayed in a very difficult to read image (vs formatted text) is simply a warning. Not an error. You have not actually shown the error. This module currently has no compilation errors that I know of, your problem is elsewhere

Thanks but i was able to resolve the error sorry for not posting question in a proper format after reinstalling fbsdk issue got resolved

@kesylo
Copy link

kesylo commented Nov 12, 2022

Any fix for expo users?

@mikehardy
Copy link
Collaborator

@kesylo of course. You have to read documentation though: https://github.com/thebergamo/react-native-fbsdk-next#expo-installation (note the access token is one of the mandatory config elements for the config plugin....)

@kesylo
Copy link

kesylo commented Nov 12, 2022

@mikehardy thanks for your quick response. So I have already installed the package and the plugin. It worked fine before on both android and IOS. but now when I do a new build on android (without changing anything) it does not work. But IOS still work. the error is: SDK has not been initialized facebookSDK.sdkInitialize()

@mikehardy
Copy link
Collaborator

You have a project-specific problem and I won't be able to help, sorry. It's important to know that this is used by lots of Expo people though, so it's possible to work if you keep digging.

@kesylo
Copy link

kesylo commented Nov 12, 2022

@mikehardy I really do need help. I have everything configured as in the docs. I use the latest version of the package "react-native-fbsdk-next": "^11.0.1".
My config is on point
[ "react-native-fbsdk-next", { scheme: facebookScheme, appID: facebookAppID, clientToken: facebookClientToken, displayName: facebookAppDisplayName, advertiserIDCollectionEnabled: true, autoLogAppEventsEnabled: true, isAutoInitEnabled: true, iosUserTrackingPermission: "This identifier will be used to deliver personalized ads to you." } ]
I don't know what else to do. this happens only on android. I just tried another ios build and it works. Any tips for me please ?

@kesylo
Copy link

kesylo commented Nov 12, 2022

For those EXPO guys out there who needs this. I fixed my issues by creating config plugins to add the values mentioned https://github.com/thebergamo/react-native-fbsdk-next/issues/236#issuecomment-1111744717 to strings.xml and adndroiManifest.xml
here are my config plugins:

(with-android-add-metadata-in-application.js)

const { withAndroidManifest } = require("@expo/config-plugins");

function addMetadataInApplication(androidManifest, attributes) {
	const { manifest } = androidManifest;

	if (Array.isArray(manifest["application"])) {
		manifest["application"].forEach(item => {
			if (Array.isArray(item["meta-data"])) {
				attributes.forEach(el => {
					item["meta-data"].push({
						$: { "android:name": el.name, "android:value": el.value }
					});
				});
			}
		});
	}

	return { manifest };
}

module.exports = function withAndroidAddMetadataInApplication(config, attributes) {
	return withAndroidManifest(config, config => {
		config.modResults = addMetadataInApplication(config.modResults, attributes);
		return config;
	});
};

(with-android-strings-xml.js)

const { AndroidConfig, withStringsXml } = require("@expo/config-plugins");

const withAndroidSplashScreen = (expoConfig, customAttributes) =>
	withStringsXml(expoConfig, modConfig => {
		// format strings
		const stringsToUpdate = [];
		customAttributes.forEach(item => {
			let stringData = { name: item.name };
			// add any extra props
			if (item.extra) stringData = { ...stringData, ...item.extra };
			// push to list
			stringsToUpdate.push({
				_: item.value,
				$: stringData
			});
		});
		// override config
		modConfig.modResults = AndroidConfig.Strings.setStringItem(
			stringsToUpdate,
			modConfig.modResults
		);
		//console.log(modConfig.modResults.resources.string);
		return modConfig;
	});

module.exports = withAndroidSplashScreen;

then in your app.js or app.config.js use the plugin like this:

[
	"./plugins/with-android-strings-xml",
	[
		{ "name": "facebook_app_id", "value": "your-facebook-id"},
		{ "name": "facebook_client_token", "value": "your-facebook-client-token"}
	]
],
[
	"./plugins/with-android-add-metadata-in-application",
	[
		{
			"name": "com.facebook.sdk.ApplicationId",
			"value": "@string/facebook_app_id"
		},
		{
			"name": "com.facebook.sdk.ClientToken",
			"value": "@string/facebook_client_token"
		}
	]
]

@mikehardy this is a real issue. please if possible, apply the fix directly in the library plugin.
I made these myself as I was blocked. It works for me. I'm not the best programmer out there but this should be fine for now.
cheers.

@mikehardy
Copy link
Collaborator

@kesylo I won't be doing that, Expo support is provided by the community and the Expo plugin will be updated via PRs provided by the community. That said, I think this is unnecessary. I believe Expo already has built in config plugin features that allow you to add things to strings.xml and AndroidManifest.xml without any additional logic in this module's config plugin. I will repeat that there are lots of Expo folks using this module already, successfully, so I think you need to look in your project and your project's use of Expo. I think you'll find that there are ways to do what you need already, and if anything the item of work here would be a documentation update (for which a PR would be happily accepted)

@kesylo
Copy link

kesylo commented Nov 12, 2022

ok @mikehardy . please can you link me to expo plugins that add values to those files? I could find them that's why I created those. thanks

@mikehardy
Copy link
Collaborator

Turns out they are all just in the existing plugin here already. No idea what's going on with your project. https://github.com/thebergamo/react-native-fbsdk-next/blob/master/plugin/src/withFacebookAndroid.ts

It's the weekend here and I don't use Expo. My support here is done, I won't respond further, I'm unsubscribing from this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests