I am trying to get LinkedIn Access Token after login. Login is working fine with JavaScript SDK and I'm able to receive "oauth_token" and member_id. I need access_token to verify the email address (if it is not forged on the way).
Below is my script:
<script>
function LoginWithLinkedIn() {
IN.User.authorize(afterAuthorization);
}
function afterAuthorization(response){
debugger
if(IN.User.isAuthorized()==true){
getProfileData();
}
}
function onSuccess(data) {
console.log(data);
}
function onError(error) {
console.log(error);
}
function getProfileData(r) {
IN.API.Profile("me")
.fields("id,firstName,lastName,email-address,picture-urls::(original),public-profile-url,location:(name)")
.result(onSuccess)
.error(onError);
}
</script>
I need help getting the access_token after successful authorization. Any help is highly appreciated!
Thanks!
Hope following code will work
function LinkedInLogin() {
IN.User.authorize(getProfileData);
}
function onSuccess(data) {
jQuery('#hdnAccessToken').val(IN.ENV.auth.oauth_token);
try {
jQuery('#hdnSocialLoginType').val('in');
jQuery('#HiddenFieldUserId').val(data.values[0].id);
jQuery('#HiddenFieldEmail').val(data.values[0].emailAddress);
jQuery('#HiddenFieldFirstName').val(data.values[0].firstName);
jQuery('#HiddenFieldLastName').val(data.values[0].lastName);
jQuery('#HiddenFieldType').val('linkedin');
jQuery('#BtnLoginSocial').click();
}
catch (err) {
alert(jQuery('#HiddenErrorMessage').val());
}
//console.log(data);
}
function onError(error) {
console.log(error);
}
function getProfileData() {
if (IN.User.isAuthorized() == true) {
IN.API.Profile("me").fields("id,firstName,lastName,email-address").result(onSuccess).error(onError);
}
}
Related
I would like to know if it's important to hide my stripe key in my javascript.
In fact, in my Symfony website, I put this key in my javascript to allow users to pay their orders.
And this is how I made that:
</footer>
</body>
<script src="https://kit.fontawesome.com/47f28c9d14.js" crossorigin="anonymous"></script>
<script type="text/javascript">
var stripe = Stripe("pk_live_....");
var checkoutButton = document.getElementById("checkout-button");
checkoutButton.addEventListener("click", function () {
fetch("/orders/create-session/154154154", {method: "POST"})
.then(function (response) { return response.json(); })
.then(function (session) { if (session.error == 'order')
{ window.location.replace('/orders'); } else { return stripe.redirectToCheckout({sessionId: session.id}); } })
.then(function (result) { if (result.error) { alert(result.error.message); } })
.catch(function(error) { console.error("Error:", error); }); });
</script>
</html>
But if you open console and check the source code you can see my stripe key...
Thanks
Yes, you can use the Stripe 'publishable' key in your client side app.
More information: https://stripe.com/docs/keys?locale=en-GB
I have been researching the google analytics api (GA4) for the past day. And I want to be able to use GA4 api functions like runReport on the client-side. There is a piece of analytics that I want each of my web-clients to see.
Here is the code that I pulled out from the gapi documentation.
<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for analyticsdata.properties.runReport
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/code-samples#javascript
*/
function authenticate() {
return gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/analytics https://www.googleapis.com/auth/analytics.readonly"})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
gapi.client.setApiKey("FILLED_THIS_WITH_MY_API_KEY");
return gapi.client.load("https://analyticsdata.googleapis.com/$discovery/rest?version=v1beta")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.analyticsdata.properties.runReport({
"resource": {}
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: "FILLED_THIS_WITH_MY_CLIENT_ID"});
});
</script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>
And it gives me this error:
gapi.auth2.ExternallyVisibleError: Invalid cookiePolicy\
Using node js i want to create persistent subscription for Azure service bus service topic. right now it is execute only once. Please guide me I am new to this. Thanks in advance. I am using following code to subscribe topic.
var azure = require('azure');
var azureConnection = "Endpoint=sb:My connection string"
var retryOperations = new azure.ExponentialRetryPolicyFilter();
var serviceBusService = azure.createServiceBusService(azureConnection).withFilter(retryOperations);
serviceBusService.receiveSubscriptionMessage('mytopic01', 'mytopicsub', function (error, receivedMessage) {
if (!error) {
// // // Message received and deleted
console.log(receivedMessage);
}
});
Also I don't want to use setInterval function. I want to solution if message publish to the topic it should automatically trigger subscription.
Actually, if your client application is an independent node.js application, we usually set up a cycle program to receive message from service bus in loop.
E.G.
var azure = require('azure');
var sbService = azure.createServiceBusService(<connection_string>);
function checkForMessages(sbService, queueName, callback) {
sbService.receiveSubscriptionMessage(queueName, { isPeekLock: true }, function (err, lockedMessage) {
if (err) {
if (err === 'No messages to receive') {
console.log('No messages');
} else {
callback(err);
}
} else {
callback(null, lockedMessage);
}
});
}
function processMessage(sbService, err, lockedMsg) {
if (err) {
console.log('Error on Rx: ', err);
} else {
console.log('Rx: ', lockedMsg);
sbService.deleteMessage(lockedMsg, function(err2) {
if (err2) {
console.log('Failed to delete message: ', err2);
} else {
console.log('Deleted message.');
}
})
}
}
setInterval(checkForMessages.bind(null, sbService, queueName, processMessage.bind(null, sbService)), 5000);
You can refer to the code sample in the similar scenario at GitHub provided by Azure Team.
Any further concern, please feel free to let me know.
I'm using the following module in my React Native app in order to login users with Facebook. https://github.com/facebook/react-native-fbsdk
I logged the following issue.
https://github.com/facebook/react-native-fbsdk/issues/58
I have the following in my view and I get the GlobalStore can't find error.
var FBSDKLogin = require('react-native-fbsdklogin');
//init facebook login
fbTouchHandler(event) {
FBSDKLoginManager.setLoginBehavior(GlobalStore.getItem('behavior', 'native'));
FBSDKLoginManager.logInWithReadPermissions([], (error, result) => {
if (error) {
alert('Error logging in.');
} else {
if (result.isCancelled) {
alert('Login cancelled.');
} else {
alert('Logged in.');
}
}
});
}
I don't know how to sync in api FB.login and here is my code:
function getAccesToken(){
var access_token = "";
FB.login(function(response) {
if (response.authResponse) {
access_token = FB.getAuthResponse()['accessToken'];
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, { scope: '' });
return access_token;
}
when I call function
var access_token = getAccessToken();
but it return empty string. How can I fix it to be synchronous?
You can't make this synchronous - and it would be extremely bad practice if you could. Instead, call a function in the FB.login callback handler that contains the access token. Try this:
function getAccesToken() {
FB.login(function(response) {
if (response.authResponse) {
loginComplete(FB.getAuthResponse()['accessToken']);
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, { scope: '' });
}
function loginComplete(token) {
console.log(token);
// do something here, now the user is logged in...
}
FB.login needs to be called on user interaction (mouse click) and you have to use the callback function of FB.login to get the Access Token asynchronously - the Access Token will be in the response value. For example:
document.getElementById('loginBtn').addEventListener('click', function() {
FB.login(function(response) {
if (response.authResponse) {
doSomethingWithTheToken(response.authResponse.accessToken);
}
}, {scope: 'email,public_profile', return_scopes: true});
}, false);
function doSomethingWithTheToken(token) {
console.log(token);
}
Source (and a lot more information about the JavaScript SDK): http://www.devils-heaven.com/facebook-javascript-sdk-login/