I am currently working on a mobile app with Nativescript. So, I do have a WebView in the main page to log in with Spotify. After the login I have to retrieve headers/queryparams from the page in the WebView. Is this possible and if, how do I do that?
You can register the loadFinishedEvent and check for the URL to get the queryparameters that are returning back to you. I am doing the same for third party login.
webViewLoaded(args) {
const webview: WebView = <WebView>args.object;
webview.on(WebView.loadFinishedEvent, (webargs: LoadEventData) => {
let message;
if (!webargs.error) {
if (webargs.url.toLowerCase().indexOf('spotity') > -1) {
//Read the parameters and navigate
}
message = 'WebView finished loading of ' + webargs.url;
} else {
message = 'Error loading ' + webargs.url + ': ' + webargs.error;
}
});
}
Related
i'm having an issue trying to use the {Linking} package. I'd like to send a text message to an specific number, like in the following code:
import { Linking } from ‘react-native’;
WhatsApp = (text, phone) => {
Linking.openURL(`whatsapp://send?text=${text}&phone=${phone}`);
}
But it happens that the message gets written in the App's text field, but I still need to press the 'send' button in order to really deliver my message. Does anybody know how to fix it? (send the message without having to press the button?)
Try this way:
WhatsApp = () => {
let msg = 'type something';
let phoneWithCountryCode = 'xxxxxxxxxx';
let mobile = Platform.OS == 'ios' ? phoneWithCountryCode : '+' + phoneWithCountryCode;
if (mobile) {
if (msg) {
let url = 'whatsapp://send?text=' + msg + '&phone=' + mobile;
Linking.openURL(url).then((data) => {
console.log('WhatsApp Opened');
}).catch(() => {
alert('Make sure WhatsApp installed on your device');
});
} else {
alert('Please insert message to send');
}
} else {
alert('Please insert mobile no');
}}
Please Note: send + in front of phone with country if opening in android
I currently have a component that requires to have a pop up upon submit. The response from the API provides a redirectURL and redirectParams to be used as the popped up window.
Simply using window.open defaults its method to GET and not POST. This causes a Not Found page whenever it is loaded this way.
This is how I currently do it:
protected makeDepositPopup(depositRequest: PaymentRequest) {
this.depositService.requestDepositPopup(depositRequest)
.subscribe(
(depositEvent: RedirectData | SuccessfulDepositPopup) => this.handleDepositPopupEvent(depositEvent),
(error: EcommError) => this.handleDepositError(error),
() => this.eventService.depositAttempt.emit()
);
}
then the event is handled via the handleDeposit event:
protected handleDepositPopupEvent(depositEvent: RedirectData | SuccessfulDepositPopup) {
if (depositEvent instanceof RedirectData) {
this.handleRedirect(depositEvent);
} else {
this.handleDepositSuccessPopup(depositEvent, this.redirectParams);
}
}
As soon as it succeeds, it then tries to open a window with the corresponding URL and parameters provided by the API response:
protected handleDepositSuccessPopup(depositEvent: SuccessfulDepositPopup, redirectParams: string): void {
redirectParams = ""; // to remove undefined value
depositEvent.params.forEach(function (data, index) {
if(index == 0) {
redirectParams += "?" + data["key"] + "=" + data["value"];
} else {
redirectParams += "&" + data["key"] + "=" + data["value"];
}
});
window.open(depositEvent.url + redirectParams);
this.router.navigate(
["deposit", this.route.snapshot.data["instrumentTypeCode"], "deposit-details", depositEvent.id], {
relativeTo: this.route.parent.parent
});
}
How do I convert this in such a way that the depositEvent.url and its appended redirectParams to open a new window with a POST method to get a successful page response?
i am developing an application and loading an hosted application using the inapp browser plugin cordova-plugin-inappbrowser
I have gotten most of the functionalities to work but i am unable to get the part of loading an error message when he url does not load, it dosent just work and shows me an error message of the url where i have hosted my application instead.
Which could be embarrassing.
please i need help on this
This is what am working with below thanks for ur potential responses
// my child browser code, the main source of my app content
function fire(){
var ref = cordova.InAppBrowser.open('http://####################', '_blank', 'location=no,zoom=no,hardwareback=yes,clearsessioncache=yes,clearcache=no');
var myCallback = function(event) { alert(event.url); }
ref.addEventListener('loadstart', inAppBrowserbLoadStart);
ref.addEventListener('loadstop', inAppBrowserbLoadStop);
ref.addEventListener('loaderror', loadErrorCallBack);
ref.addEventListener('exit', inAppBrowserbClose);
}
function loadErrorCallBack(params) {
$('#status-message').text("");
var scriptErrorMesssage =
"alert('Sorry we cannot open that page. Message from the server is : "
+ params.message + "');"
inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);
inAppBrowserRef.close();
inAppBrowserRef = undefined;
}
function executeScriptCallBack(params) {
if (params[0] == null) {
$('#status-message').text(
"Sorry we couldn't open that page. Message from the server is : '"
+ params.message + "'");
}
}
Your code is generally fine, but you have no control over the title of the alert() function. You can use some other techniques to display the error message. For example, you can use a div:
function loadErrorCallBack(params) {
$('#status-message').text("");
var scriptErrorMesssage = createMsg('Sorry we cannot open that page. Message from the server is: '
+ params.message);
inAppBrowserRef.executeScript({
code: scriptErrorMesssage
}, executeScriptCallBack);
inAppBrowserRef.close();
inAppBrowserRef = undefined;
}
function createMsg(msg) {
return 'var div = document.createElement("div");'
+ 'div.style.position = "absolute";'
+ 'div.style.top = "50%";'
+ 'div.style.left = "50%";'
+ 'div.style.width = "100px";'
+ 'div.style.height = "100px";'
+ 'div.style.color = "#f00";'
+ 'div.innerHTML = "' + msg + '";'
+ 'document.appendChild(div);'
}
I'm using javascript with drive + spreadsheet api. Now I am able to get the access token. But I tries a lot with stack answers and google guide for get refresh token request. But I did not found any way that how to access the refresh token by access token. Please help me with some code.
My script is:
var _url = https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email&client_id={my_client_id}&client_secret={My_secret_key}","redirect_uri=httpmypath to currentrunningfile/oauth&response_type=token
function getAccessDetails() {
var win = window.open(_url, "windowname1", 'width=800, height=600');
var pollTimer = window.setInterval(function() {
try {
console.log(win.document.URL);
if (win.document.URL.indexOf(REDIRECT) != -1) {
window.clearInterval(pollTimer);
var url = win.document.URL;
console.log('url is :'+url);
acToken = gup(url, 'access_token');
tokenType = gup(url, 'token_type');
expiresIn = gup(url, 'expires_in');
console.log('acToken :' + acToken + 'tokenType :' + tokenType + 'expiresIn :' + expiresIn);
win.close();
validateToken(acToken);
}
} catch(e) {
}
}, 500);
}
What is the next step and how to code it for access the refresh token? Actully I want user to login first time to app with their google login details for their drive files access by my app. The next time when user use my app to access his drive files. He can access files without login.
I have a metro app developed with WinJS in VS2012 and I want to open this address
window.location = "http://XXX.XXX.XX.XXX:XXXX/test/AU/jsp/AU000007.jsp";
this works ok, opens the webpage on new browser from my metro app
But I want to add several parameters encrypted by using jcrypto so I do this:
//message encryption
message = jcrypto(message);
message = "http://XXX.XXX.XX.XXX:XXXX/test/AU/jsp/AU000007.jsp?data=" + message;
window.location = message;
but it just opens the link on my metro app, how to fix that???
UPDATE: thanks to WiredPrairie's suggestion I found this answer:
var uri = new Windows.Foundation.Uri("http://XXX.XXX.XX.XXX:XXXX/test/AU/jsp/AU000007.jsp?data=" + jcrypto(message));
//opens the url on external browser
Windows.System.Launcher.launchUriAsync(uri).done(
function (success) {
if (success) { console.log("page opened correctly"); }
else { console.log("an error has occured"); }
});
try with this other:
//message encryption and URL addition
message = "http://XXX.XXX.XX.XXX:XXXX/test/AU/jsp/AU000007.jsp?data=" + jcrypto(message);
window.open(message, "_blank", "fullscreen=yes,height=600,width=800,scrollbars=yes,resizable=no");