Ionic - Facebook Native Ads Error 1001 (No fill) - facebook

My facebook native ads integration code is like below.
var that = this;
this.platform.ready().then(() => {
if(FacebookAds)
{
//FacebookAds.setOptions({
//isTesting: true,
//deviceHash: 'fe645f07-9801-41fe-a430-xxxxxxxxxxx'
//},(s)=>(console.log("settings are OK.")),(e)=>(console.log("Settings are not loaded...")));
FacebookAds.createNativeAd('xxxxxxxxx',
(eee) => {
document.addEventListener("onAdLoaded", (data) =>{
console.log(data);
let temp: any = data;
if(temp.adType == "native")
{
this.startFB = 1;
document.getElementById('adIcon').setAttribute("src", decodeURIComponent(temp.adRes.icon.url));
document.getElementById('adCover').setAttribute("src", decodeURIComponent(temp.adRes.coverImage.url));
document.getElementById('adTitle').innerHTML = temp.adRes.title;
document.getElementById('adBody').innerHTML = temp.adRes.body;
document.getElementById('adSocialContext').innerHTML = temp.adRes.socialContext;
document.getElementById('adBtn').innerHTML = temp.adRes.buttonText;
that.updateXY(0, 0);
}
});
document.addEventListener('onAdFailLoad', (data) => {
console.log(data);
//alert('error: ' + data);
});
},
(err) => console.log(err)
);
}
});
When I run this code without test mode, I get 1001 error code.
When I run this code with test mode, No error but load data comes empty.
Not: I test code in real device and I login as test user to Facebook app in this device.
Do you have any advice?

Related

React-native Log in with Facebook App refreshes app

I am using react-native-fbsdk and am on IOS. When users log in with Facebook their are two buttons they can press. Log in with the Facebook App or Log in with Phone Number or Email Address. Logging in with the Phone Number or email address works perfectly, I get the user object and create a user account for them. But when users press Log in with the Facebook App I don't get sent a user object, and the whole app refreshes where they get pushed to the log in page and the Facebook button has turned to Log out. I am not too sure on how to approach this as when users log in with the Facebook App none of my console.logs or alerts are getting called and the whole app just refreshes. Any help would be very much appreciated.
<LoginButton
readPermissions={["email","public_profile"]}
onLoginFinished={
(error, result) => {
console.log("onLoginFinished: ", result);
if (error) {
console.log("login has error: ", result.error);
} else if (result.isCancelled) {
console.log("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
let accessToken = data.accessToken
console.log("accessToken.toString(): ", accessToken.toString())
const responseInfoCallback = (error, result) => {
if (error) {
console.log('Error fetching data: ', error)
//lert('Error fetching data: ' + error.toString());
} else {
console.log("responseInfoCallback:", result)
this.state.fbobj = result;
this.sendAjax();
//alert('Success fetching data: ' + result.toString());
}
}
const infoRequest = new GraphRequest(
'/me',
{
accessToken: accessToken,
parameters: {
fields: {
string: 'email,name'
}
}
},
responseInfoCallback
);
// Start the graph request.
new GraphRequestManager().addRequest(infoRequest).start()
}
)
}
}
}
onLogoutFinished={() => console.log("Logout")}
In your button action, you will need something like this:
import { LoginManager, AccessToken } from 'react-native-fbsdk'
handlePressFacebookLogin = () => {
LoginManager.logInWithReadPermissions(['public_profile', 'email']).then(
(result) => {
if (!result.isCancelled) {
AccessToken.getCurrentAccessToken().then((data) => {
console.log(data)
})
}
}
)
}

Error API Facebook - Angular 2 and Ionic 2

I'm working with the facebook API and I need to get the profile data to save it in a database. The code returns fine, but when I try to access the data it shows me error because they are null.
This is my code:
this.fb.login(['public_profile', 'user_friends', 'email'])
.then((res: FacebookLoginResponse) => {
token = res.authResponse.accessToken;
userId = res.authResponse.userID;
if (res.status == 'connected') {
this.fb.api('/' + res.authResponse.userID + '?fields=id,first_name,last_name,gender, email,birthday', [],
function onSuccess(result) {
var name = JSON.stringify(result.first_name);
this.register(name);
},
function onError(error) {
console.log(error);
});
} else {
console.log('Not logged in');
}
}).catch(e => console.log('Error logging into Facebook', e));
When I try to call the register method it generates error because the method does not exist, but this is not true. I also tried to save the result of name to a global variable but when it is to be assigned it shows that it can not assign the variable, ie as if the global variable was not defined.
The solution was to change
function onSuccess(result) {
var name = JSON.stringify(result.first_name);
this.register(name);
},
function onError(error) {
console.log(error);
});
for
(result) => {
var name = JSON.stringify(result.first_name);
this.register(name);
},
(error) => {
console.log(error);
});

File Transfer , onProgress not working on iOS ( IONIC3 )

I been working with fileTransfer from Ionic native, it working fine on Android, but on iOS not not do anything at all
Here is my code:
getFile(fileName,url){
let fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.download(url, this.file.dataDirectory + fileName).then((entry) => {
console.log('entry:',entry)
}, (error) => { console.log(error); });
console.log('file transfer',fileTransfer.onProgress)
var a = fileTransfer.onProgress((progressEvent: ProgressEvent) => {
this.ngzone.run(() => {
console.log(progressEvent.loaded)
});
});
}
it depends on how to derive this.file.dataDirectory.
In my case it always works like this ..
declare var cordova:any; //on top of file
if (this.platform.is('android')) {
this.fsurl = cordova.file.dataDirectory;
}else{
this.fsurl = cordova.file.documentsDirectory;
}

Linkedin ionic2 authentication

Can anybody help me with Ionic2 LinkedIn authentication without using ionic services, stamplay or AuthO, I have written the code, configured the app on linkedin, but it seems there is a problem with it(configuration) as the LinkedIn Popup opens but doesn't generates any response after entering credentials.
Note : I have used stamplay for linkdin
// install cordova-plugin-inappbrowser
declare var window: any;
export class HomePage {
constructor(public platform: Platform,private http: Http) {
this.platform = platform;
this.http = http;
}
linkedlogin()
{
this.platform.ready().then(() => {
this.linked().then(success => {
//Generate to the access token
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
let options = new RequestOptions({ headers: headers });
this.http.get("https://www.linkedin.com/oauth/v2/accessToken?client_id='Your clientID'&client_secret='your client_secret'&redirect_uri=https://ionic-li-login.stamplayapp.com/auth/v1/linkedin/connect&code="+ success + "&grant_type=authorization_code",
options).map( res =>res.json()).subscribe(data =>
{
var accessToken = data.access_token;
//Get to the people data for login user data
this.http.get("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,industry,picture-url,headline,date-of-birth,location:(name))?format=json&oauth2_access_token=" + accessToken )
.map( res =>res.json())
.subscribe(showdata => {
var linkdata = {
id:showdata.id,
firstName:showdata.firstName,
lastName:showdata.lastName,
emailAddress:showdata.emailAddress,
industry:showdata.industry,
headline:showdata.headline,
location:showdata.location.name,
pictureUrl:showdata.pictureUrl,
}
console.log(JSON.stringify(linkdata));
});
});
}, (error) => {
alert('Error');
});
});
}
linked(): Promise<any>
{
return new Promise(function(resolve,reject)
{
/* Linkedin login and signup page */
var browserRef = window.cordova.InAppBrowser.open("https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id='your clientID'&redirect_uri=https://ionic-li-login.stamplayapp.com/auth/v1/linkedin/connect&scope=r_basicprofile+r_emailaddress");
browserRef.addEventListener("loadstart", (event) => {
if ((event.url).indexOf("https://ionic-li-login.stamplayapp.com/auth/v1/linkedin/connect") === 0)
{
browserRef.removeEventListener("exit", (event) => {});
browserRef.close();
/* Will be generate to the authentication code */
var authcode = (event.url).split("code=")[1];
if(authcode !=null)
{
resolve(authcode);
}
else
{
alert("Problem authenticating with Linkdin");
}
}
});
browserRef.addEventListener("exit", function(event)
{
reject("The Linkdin sign in flow was canceled");
});
});
}
}

Integrating Branch.io in Ionic App

I am trying to send my app's link form my website with a token in the link like this :
branch.link({
stage: 'new user',
data: {
token: 543322
}},
function(err, link) {
console.log(err, link);
});
then when the app is installed by user after clicking on the link, i want to get this token to register the user.
I tried by reading Branch.io docs and implementing it but it's not working.
Can somebody tell me an Example to how to make it work?
Code in my app controller is like this
(():void => {
'use strict';
angular
.module('xyz')
.controller('abc', abc);
function abc (
$window
) {
let vm = this;
$window.Branch.setDebug(true);
$window.Branch.initSession().then(function (res) {
console.log(res);
alert('Response: ' + JSON.stringify(res));
}).catch(function (err) {
console.error(err);
alert('Error: ' + JSON.stringify(err));
});
$window.Branch.getFirstReferringParams().then(function (res) {
// Success Callback
alert('res'+res);
}).catch(function (err) {
// Error Callback
alert('err'+err);
});
$window.Branch.getLatestReferringParams().then(function (res) {
// Success Callback
alert(res);
}).catch(function (err) {
// Error Callback
alert(err);
});
function DeepLinkHandler (data) {
alert('Data from initSession: ' + data.data);
}
$window.DeepLinkHandler = DeepLinkHandler;
})();
Alex from Branch here: there are three steps to this process:
1. Create the link
You're doing this already with the code you provided in your question.
2. Integrate the Branch SDK into your app
The docs page covering the steps for this is here: https://dev.branch.io/getting-started/sdk-integration-guide/guide/cordova/
3. Watch for the incoming link, and route it
The docs page covering what you need for this is here: https://dev.branch.io/getting-started/deep-link-routing/advanced/cordova/
Basically, it is a function that will look something like this:
function DeepLinkHandler(data) {
console.log("received data: " + JSON.stringify(data));
for (key in data) {
if ((key != "type" && key != "source" && key != "bubbles" && key != "cancelBubble") && data[key] != null) {
console.log(key + ": " + data["key"]);
}
}
if (data["token"]) {
// load the view to register the user based on your token
} else {
// load your normal view
}
}