Using client.js library for Trello API - javascript

I'm new with trello API.
As suggested by Trello, I'm trying to use the client.js library.
I followed the instructions, and i get a 'Successful authentication' message in the console, but yet I get a 401 error(in the console):
POST https://api.trello.com/1/cards 401 () jquery-1.7.1.min.js:4
Here is my code:
<head>
<title>Trello api</title>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="https://api.trello.com/1/client.js?
key=[my key]"></script>
</head>
<body>
<script>
var authenticationSuccess = function() { console.log('Successful
authentication'); };
var authenticationFailure = function() { console.log('Failed
authentication'); };
Trello.authorize({
type: 'popup',
name: 'Getting Started Application',
scope: {
read: true,
write: true },
expiration: 'never',
success: authenticationSuccess,
error: authenticationFailure
});
var myList = 'my list';
var creationSuccess = function(data) {
console.log('Card created successfully. Data returned:' +
JSON.stringify(data));
};
var newCard = {
name: 'New Test Card',
desc: 'This is the description of our new card.',
idList: myList,
pos: 'top'
};
Trello.post("cards", newCard, creationSuccess);
</script>
Any ideas?
Thanks.

I had the same issue. I take 'login' and 'logout' from http://jsfiddle.net/A3Xgk/2/ , and it is working.
Trello.authorize({
interactive: false,
success: onAuthorize
});
$("#connectLink").click(function() {
Trello.authorize({
type: "popup",
success: onAuthorize
});
});
If it will not help, please write me, I give to you my code.

Related

JQuery.Ajax() not working not sure if script is loading properly

I'm trying to use an API to send emails through MailChimp. I can avoid using any sort of back end by doing this. I don't know if I am setting up my Jquery script file wrong.
$(document.ready(function () {
$('#survey').click(function() {
$.ajax({
type: “POST”,
url: “https://mandrillapp.com/api/1.0/messages/send.json”,
data: {
‘key’: ‘api Key’,
‘message’: {
‘from_email’: ‘email’,
‘to’: [
{
‘email’: ‘email’,
‘name’: ‘RECIPIENT NAME (OPTIONAL)’,
‘type’: ‘to’
}
],
‘autotext’: ‘true’,
‘subject’: ‘Class Survey’,
‘html’: ‘Here is your survey link: <a>link</a>’
}
}
}).done(function(response) {
console.log(response);
});
});
});
Here are all the errors I am receiving in VS Code
I am not sure why VS Code is highlighting all of the code. I also wanted to mention the console is giving this error even though it doesnt give much info.
Uncaught SyntaxError: Invalid or unexpected token
Thanks for the help!
it's because of the wrong double quotes you are using
use this " instead of this “
use this ' instead of ‘
$(document).ready(function() {
$('#survey').click(function() {
$.ajax({
type: "POST",
url: "https://mandrillapp.com/api/1.0/messages/send.json",
data: {
'key': 'api Key',
'message': {
'from_email': 'email',
'to': [
{
'email': 'email',
'name': 'RECIPIENT NAME (OPTIONAL)',
'type': 'to'
}
],
'autotext': 'true',
'subject': 'Class Survey',
'html': 'Here is your survey link: <a>link</a>'
}
}
}).done(function(response) {
console.log(response);
});
});
});

Stripe checkout - IE popup is blocked on second payment

O/S: BrowserStack Live
Browser: IE11
I am using Stripe checkout with js sdk to display a popup when the user clicks a button. The code is as follows:
Payment.prototype = {
pay: function (options, callback) {
let tokenTriggered = false;
_handler = StripeCheckout.configure({
key: Constants[Constants.ENV].STRIPE_KEY,
image: 'image.jpg',
locale: 'auto',
token: function token(token) {
tokenTriggered = true;
const data = {
stripeToken: token.id,
stripeEmail: token.email,
amount: options.amount,
currency: CURRENCY,
capture: options.capture
};
$.ajax({
type: 'POST',
data: JSON.stringify(data),
contentType: 'application/json',
url: '/api/stripe',
success: function success(charge) {
callback(null, charge);
},
error: function error(error) {
callback(error.responseText);
}
});
},
closed: function () {
if (!tokenTriggered) {
// close button click behavior goes here
callback(1);
}
}
});
},
open: function (amount, name, description) {
// Open Checkout with further options:
_handler.open({
name: name,
description: description,
zipCode: true,
currency: 'aud',
amount: amount
});
}
};
The 'pay' function is invoked followed by the 'open' function. The workflow of my app requires the user to pay for stuff twice in one session. In IE11, no Stripe popup is displayed on the second payment. Any ideas?
The following url https://stripe.com/docs/checkout explains that the 'handler.open' code shouldn't be in a callback which it isn't.
The console error is: "SCRIPT70: Permission denied".
** EDIT 07/03/2017 **
This error is only occurring when: a payment is made, another page is navigated to, then another payment is attempted.
I resolved this by initialising the StripeCheckout only once when the site is loaded. I then moved the functionality from "StripeCheckout.configure" into the "handler.open" function and invoked that whenever I need a payment.
init: function () {
_handler = StripeCheckout.configure({
key: Constants[Constants.ENV].STRIPE_KEY,
image: 'image.jpg',
locale: 'auto'
});
},
open: function (options, callback) {
let tokenTriggered = false;
// Open Checkout with further options:
_handler.open({
name: 'An app',
description: options.description,
zipCode: true,
currency: CURRENCY,
amount: options.amount,
token: function token(token) {
tokenTriggered = true;
const data = {
stripeToken: token.id,
stripeEmail: token.email,
amount: options.amount,
currency: CURRENCY,
capture: options.capture
};
$.ajax({
type: 'POST',
data: JSON.stringify(data),
contentType: 'application/json',
url: '/api/stripe',
success: function success(charge) {
// _instantiated = true;
callback(null, charge);
},
error: function error(error) {
callback(error.responseText);
}
});
},
closed: function () {
if (!tokenTriggered) {
// close button click behavior goes here
callback(1);
}
}
});
},

How to display following response using vue js?

This is my response.. How to display the error message? passwords do not match
{"errors": {"password": ["Passwords donot match"]}, "status": false, "msg": "Validation erro", "error-type": 0}
Currently my code is
<script>
regBox = new Vue({
el: "#regBox",
data: {
..........
response: {
message: '',
status: '',
state: '',
errors: '',
}
},
methods: {
handelSubmit: function(e) {
var vm = this;
data = {};
..............
$.ajax({
url: '',
data: data,
type: "POST",
dataType: 'json',
success: function(e) {
if (e.status)
{
alert(" Success")
}
else {
vm.response = e;
alert(" Failed")
}
}
});
return false;
}
},
});
</script>
My html code to display the same is
<p class="error">{{response.errors.password}}</p>
Currently i am getting error message as
["Passwords donot match"]
How to get only message as
Passwords donot match.. so, how can i able to get it.. can anybody help
This should work:
<p class="error">{{response.errors.password[0]}}</p>
Get the first element
<p class="error">{{response.errors.password[0]}}</p>

Send wall message to multiple users using facebook javascript sdk

I'm trying to send from one site to post a message on a wall of multiple users using the facebook js sdk.
I have an issue, it seems we cannot put multiple 'to' recipients in the js code provided.
Is there any solution please?
The code I have:
$(document).ready(function () {
$('form').bind('submit', function () {
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
}
});
var chkArray = [];
$(".fb_friend :checked").each(function () {
FB.ui({
method: 'feed',
name: 'Event On GiFolio !',
link: 'https://developers.facebook.com/docs/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: '',
description: 'Click on the link to join my event on GiFolio !',
to: $(this).val()
}, function(response){
console.log(response);
});
});
return false;
});
});
Img:

How to get FB.api('/me/feed', 'post', ... to work?

I've tried to use FB.api to post something to my feed for hours now. I can't get it to work for me. I gave the permissions to the app. I can post to my feed with the PHP SDK but I have to use JavaScript.
<button onclick="doPost()">Post to Stream</button>
<script>
window.doPost = function() {
FB.api(
'/me/feed',
'post',
{ body: 'Trying the Graph' },
Log.info.bind('/me/feed POST callback')
);
};
</script>
Can someone give me the example of a simple HTML page that uses FB.api to post to a feed?
Well, I got it working myself. I'm not sure what was wrong the first time as I started from scratch with a new HTML file. I hope it will help someone:
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
</head>
<body>
Post to Facebook
<script>
function postToFacebook() {
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { body: body, message: 'My message is ...' }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response);
}
});
}
</script>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR APP ID GOES HERE',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
</body>
</html>
I use this code on fb game-app
and looks like this http://trupa.files.wordpress.com/2012/04/prscreenan.jpg
<br><font style="color:#FFF; text-decoration:none;padding-left:27px;">post to wall</font><br>
<script>
function publishStory() {
FB.ui({
method: 'feed',
name: 'message name',
caption: 'message caption ',
description: 'description goes here',
link: 'the url current page',
picture: 'if you want to add an image'
},
function(response) {
console.log('publishStory response: ', response);
});
return false;
}
</script>
In first example you forgot "message" property. With out "message" you can post everyone, but not self.

Categories

Resources