type error null is not an object (evaluating 'ShareDialog.canShow') in React Native FBSDK - ios

I have followed this GitHub URL to integrate Facebook sharing in my application.
https://github.com/facebook/react-native-fbsdk
Here is my code:
constructor(props){
super(props);
this.state={
shareLinkContent : {
contentType: 'link',
contentDescription: 'Facebook sharing is easy!',
contentUrl: 'https://cabbazar.com',
},
}
shareLinkWithShareDialog() {
var tmp = this;
ShareDialog.canShow(tmp.state.shareLinkContent).then(
function(canShow) {
if (canShow) {
return ShareDialog.show(tmp.state.shareLinkContent);
}
}
).then(
function(result) {
console.log('handle result: ' + result);
},
function(error) {
console.log('Share fail with error: ' + error);
}
);
}
But I am always getting an error in my simulator. Do I need to setup anything in for Xcode?
I checked this url but it is not solving my problem.
null is not an object (evaluating 'ShareDialog.canShow')
Please suggest.
Thanks

Sometimes auto link doesn't work. So you have to link manually using react-native link react-native-fbsdk

Related

react-native error RCTJSONStringify() encountered the following error: Invalid type in JSON write (NSURL)

I am trying to use react-native-fbsdk in my react-native app. It was working fine untill yesterday. But, today it gives a weird error stating RCTJSONStringify() encountered the following error: Invalid type in JSON write (NSURL).
RN v0.42.0
Here is my code:
_fbAuth(error, result) {
if (error) {
console.log("error");
alert("login has error: " + result.error);
} else if (result.isCancelled) {
console.log("login cancelled");
alert("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then((data) => {
console.log("login success");
console.log(data.accessToken.toString());
let accessToken = data.accessToken;
alert(data.accessToken.toString());
const responseInfoCallback = (error, result) => {
if (error) {
console.log(error);
} else {
console.log(result);
}
}
const infoRequest = new GraphRequest(
'/me',
{
accessToken: accessToken,
parameters: {
fields: {
string: 'email,name,first_name,middle_name,last_name'
}
}
},
responseInfoCallback
);
// Start the graph request.
new GraphRequestManager().addRequest(infoRequest).start();
});
}
}
render() {
console.log("in new render");
return (
<View style={styles.container}>
<LoginButton
publishPermissions={["publish_actions"]}
onLoginFinished={this._fbAuth}
onLogoutFinished={() => alert("logout.")}/>
</View>
);
}
The error information printed in debugger:
I get the above error while calling the graphAPI in the function responseInfoCallback. Any ideas what is happening ?
Update 1:
This error happens only when remote debugger is turned on!! Else it is not happening. But without remote debugger, I cannot proceed with developing the app. Are there any other methods to see log statements of react-native app other than remote debugger ?
Update 2:
The RCTJSONStringify() error happens only behind proxy. And also https fetch calls does not work under proxy. I tested in an open network, it works fine. I guess, it is to add some proxy information to RN app. I think it is related to APP transport security
If you turn the debugger off, you can see the proper error in the XCode console. Access it from Xcode menu View/Debug Area/Activate console, if it's not enabled automatically.

react-native-fbsdk not returning email

I have integrated the react-native-fbsdk library and getting user profile info such as name, middle name etc except email
i have tried readPermissions={["email,"public_profile","friends"]}
Then too not getting email
Any help would be appreciated.
Thanks in advance
I'm facing the same issue and it looks like the only workaround is using the LoginManager class provided by react-native-fbsdk.
import {
LoginManager,
} from 'react-native-fbsdk';
const _fbLogin = () => {
LoginManager.logInWithReadPermissions(['public_profile', 'email']).then(
(result) => {
if (result.isCancelled) {
alert('Login cancelled');
} else {
alert('Login success with permissions: ' + JSON.stringify(result));
}
},
(error) => {
alert('Login fail with error: ' + error);
}
);
}
And you can try using that _fbLogin function as an event handler for a custom button. I did not find how to use it with the blue, out of the box facebook Log in button.
Hope it helps!
readPermissions has now been replaced with permissions
<LoginButton
permissions={["email", "user_friends", "public_profile"]}
onLoginFinished={this._onFacebookLoginFinished.bind(this)}
onLogoutFinished={this._onFacebookLogoutFinished.bind(this)}
/>
Once you've completed a login and have an access token, you need to use the Graph API https://github.com/facebook/react-native-fbsdk#graph-api to retrieve data
you can find explaination for it here

Cordova/Ionic Facebook getLoginStatus not working

I am developing an App in Ionic/Cordova with Login over Facebook. Before showing the "Login-Page" I would like to check if the user is already connected.
The following getLoginStatus check works as expected in the iOS Simulator. When testing on the actual device, the getLoginStatus callback does not get fired.
facebookConnectPlugin.getLoginStatus(
function (response) {
if (response.status == "connected") {
set_tokens(response);
$location.path('/tab/person/me/events');
}
},
function (response) { alert(JSON.stringify(response)) }
);
Already set the Facebook-App to public and verified the App-Id.
Can anybody give a reason for the described behaviour?
I have the following implementation for Facebook login using facebookConnect Plugin.
facebookConnectPlugin.getLoginStatus(
function(response){
if(response.status == "connected"){
//do something, for example share or redirect
}else{
facebookConnectPlugin.login(["basic_info"],
function(success) { /*do something...*/},
function(error) {
//handle error
});
}
}, function(error) {
// handle error
})
}
If you still have errors, try to log the error and success events to see what is happening. This implementations works in a controller.

ionic/AngularJS OK in Chrome, Can't find variable :$ in iOS Simulator

Im currently using Ionic framework (inc AngularJS) with PhoneGap to develop a mobile application.
When running in chrome the application works seamlessly (I have been debugging the errors while in development).
I deployed to the iOS simulator today and hooked it upto safari developer tools and got the follow error.
Error: Can't find variable: $
My controllers etc work fine here however my postLogin() function does not.
Here is a cutdown version of my LoginController, Am i not passing $ correctly?
.controller('LoginCtrl', function($http, $ionicLoading, $scope, $state) {
$scope.login = {};
$scope.handlerLogin = function(response){
$ionicLoading.hide();
if(response.data.response == 1){
localStorage.setItem("token",response.data.token);
$state.go("app.search", {}, {reload: true});
}else if(response.data.response == 0){
$scope.login.password = '';
$('#errorMessageText').text('Login failed. Please try again.');
$('#errorMessage').fadeIn(2000, function(){$('#errorMessage').fadeOut('slow');});
}else{
//handle general error?
}
}
$scope.postLogin = function() {
$ionicLoading.show({
template: 'loading'
});
var formdata = $scope.login;
var url = api + 'api/login';
$.ajax({
type: "GET",
url: url,
data: formdata,
success: function success(data){
$scope.handlerLogin(data);
},
dataType: 'jsonp'
});
};
$scope.doLogin = function() {
if($scope.login.email == null || $scope.login.password == null){
$('#errorMessageText').text('Please complete both fields.');
$('#errorMessage').fadeIn(2000, function(){$('#errorMessage').fadeOut('slow');});
}
else{
$scope.postLogin();
}
}
});
Please ignore than im using JSONP for logging in for now.
Any pointers would be a great help! Scratching my head for hours now!!

The operation couldn’t be completed. (com.facebook.sdk error 5.)

I have a problem when created a new app in facebook and use it for sharing in Titanium with the Facebook Module , i get this error :
Error: HTTP status code: 403
[ERROR] : FB: The operation couldn’t be completed. (com.facebook.sdk error 5.)
So if i used my old (other) appid with the same code and and the same config in facebook apps section it works fine.
var fb = require('facebook');
fb.appid = "XXXXXXXXXXXXXXX";
fb.permissions = ['publish_stream', 'read_stream'];
if(!fb.loggedIn) {
fb.authorize();
}
var data = {
message: messageToShare,
picture: blobImageToShare
};
fb.requestWithGraphPath('me/photos', data, "POST", function(e){
if (e.success) {
Ti.API.info("FB: Success! Shared to FB: " + e.result);
}
else {
if (e.error) {
Ti.API.error('FB: '+ e.error);
}
else {
Ti.API.error("FB: Unkown result sharing");
}
}
});
Titanium version : 3.3.0
Titanium SDK 3.3.0
Platform & version : iOS >=6
Device: iOS simulator, iPhone 4 & 5.
any solution for this problem ?
You need to make sure the Facebook authorization completes before attempting to do a Graph query.
fb.authorize();
fb.addEventListener('login', function(e) {
Ti.API.debug('Returned from Facebook.');
if (e.success) {
Ti.API.debug('Authorized with Facebook, yeeey!');
// Query Graph now that we're authorized...
}
else if (e.error) {
Ti.API.debug('Error logging in with Facebook: ' + e.error);
}
else if (e.cancelled) {
Ti.API.debug('Cancelled logging in with Facebook.');
}
else {
Ti.API.debug('Something else. May actually be logged out.');
}
});
Also, make sure you define your Facebook appid in your tiapp.xml file:
<property name="ti.facebook.appid">xxxxxxxxxxxx</property>

Resources