I am trying to access the Appcelerator Titanium SDK for ACS after authenticating a user through Social Integrations. I am using the following code, which is copied line for line from the ACS Kitchen Sink example application, and I still cannot get it to work. The call to log the user in is successful, but the subsequent call to PhotoCollections API returns "404 - Failed to Authenticate user".
I am using oauth 3 legged authentication with the User Authentication Scheme set to Authorization Server. I have also tried other ACS APIs, without any luck. Please help! I've been stuck on this for 2 weeks now.
fb.addEventListener('login', function(e) {
if (e.success) {
Cloud.SocialIntegrations.externalAccountLogin({
type : 'facebook',
token : fb.accessToken
}, function(e) {
if (e.success) {
var user = e.users[0];
Cloud.PhotoCollections.create({
name : 'Party Pictures'
}, function(e) {
if (e.success) {
var collection = e.collections[0];
alert('Success:\n' + 'id: ' + collection.id + '\n' + 'name: ' + collection.name + '\n' + 'count: ' + collection.counts.total_photos + '\n' + 'updated_at: ' + collection.updated_at);
} else {
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
} else {
alert('Error: ' + ((e.error && e.message) || JSON.stringify(e)));
}
});
}
});
Turns out that multiple posts online were wrong about the server configuration needed to do this. Make sure that your "User Authentication Scheme" is set to "API Server" and not "Authorization Server". It turned out to be that simple for me.
Related
After successfully log in, i try to get a few fields from the user.
All of them are undefined other than the name and ID. The pop up indeed ask those permission which I granted.
Read all posts here and non offered a solution that work other than using tokens(?) which I am not sure how, and never see in FB examples.
FB.login(
function(response) {
if (response.status === "connected") {
console.log("connected");
console.log("Access Token: " + response.authResponse.accessToken);
testAPI();
} else {
console.log("not connected");
}
},
{ scope: "email,user_age_range,user_friends" }
);
function testAPI() {
console.log("Welcome! Fetching your information.... ");
FB.api("/me", function(response) {
console.log("name: " + response.name);
console.log("email: " + response.email);
console.log("id: " + response.id);
console.log("friends: " + response.user_friends);
console.log("age: " + response.user_age_range);
console.log("end");
});
}
If I print response i get an error :
Uncaught ReferenceError: respond is not defined
To anyone who wonder, first, the way to read it is :
FB.api('/me', {fields: 'name,email'}, (response) => {
console.log('name: ' + response.name);
console.log('email: ' + response.email);
});
Second, a few points to notice:
Remove your app on your facebook profiles (under Apps) otherwise every time you test, FB will automatically grant access even if you wish to add more permissions.
Remove cache from your browser every new test because FB will keep the previous state and changes will not take effect.(sometimes, even updated deployments will not)
You should deploy your website, with me - local host is not working with FB because they require https.
Testing Facebook is a little bit hassle.
I am developing a SAPUI5-App. Is there a way to show all errors directly to the customer without having to put a try-catch-block into every callback of sapui5? He will use my app in a mobile device and wouldn´t be able to see the log.
I tried already the following code:
<script type="text/javascript">
window.onerror = function(msg, url, line, col, error) {
var extra = !col ? '' : '\ncolumn: ' + col;
extra += !error ? '' : '\nerror: ' + error;
alert("Error: " + msg + "\nurl: " + url + "\nline: " + line + extra);
return false; //true = suppress error alert
};
window.addEventListener("error", handleError, true);
function handleError(evt) {
if (evt.message) {
alert("error: "+evt.message +" at linenumber: "+evt.lineno+" of file: "+evt.filename);
} else {
alert("error: "+evt.type+" from element: "+(evt.srcElement || evt.target));
}
}
jQuery.sap.log.addLogListener({
onLogEntry : function(oLogEntry) {
if(oLogEntry.level == '1'){
alert(oLogEntry.details + ' - '+oLogEntry.message);
}
}});
</script>
But I like to actually copy the error-message from the log into an alert for the customer, so he can send me screenshots of the error in his device.
All my attempts did not show enough information or didn´t fire on every error in the console-log.
I'm reading this interesting part of FB:
[https://developers.facebook.com/docs/sharing/opengraph/object-api#objectapi-images]
My goal is to sent a custom object to graph api explorer, completed of a staged image.
Please have a look to the FB documentation, paragraph about staging images.
I want to stage the image, get it later, and then compose an object with the staged image and push it to the graph api as a story.
There is only one example in CURL.
I would like to use FB.api().
I've been trying to do something like:
FB.api(
'https://graph.facebook.com/me/staging_resources',
'post',
{'file' : '#images/prawn-curry-1.jpg',
'access_token' : $USER_ACCESS_TOKEN},
function(response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
document.getElementById('result').innerHTML =
'Error: ' + response.error.message;
} else {
document.getElementById('result').innerHTML =
'<a href=\"https://www.facebook.com/me/activity/' +
response.id + '\">' +
'Story created. ID is ' +
response.id + '</a>';
}
}
);
but it does not like it, although the access_token is the appID.
I thought the access_token will be held in request and tried:
FB.api(
'https://graph.facebook.com/me/staging_resources',
'post',
{'file' : '#images/prawn-curry-1.jpg'},
function(response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
document.getElementById('result').innerHTML =
'Error: ' + response.error.message;
} else {
document.getElementById('result').innerHTML =
'<a href=\"https://www.facebook.com/me/activity/' +
response.id + '\">' +
'Story created. ID is ' +
response.id + '</a>';
}
}
);
but it does not take the image, neither with an absolute url.
(I guess the syntax #images/ means a relative url to the path, I've never seen it in this context).
Could you please tell me what is wrong here for staging an image with
javascript?
Can I post an image in Base64 or is the protocol the same
of /graph/me/photo? api ? I am trying to upload from canvas :)
Can you clarify how to call the image and compose the object story? It is not clear if the staged image will only be present temporarily, so to update the same object, or I can store indefinite objects, so that I should take care of naming.
In the link above, it looks like it query by image filename, and it is not clear to me if I can fetch *by ID * (exact matching) after response is successful so to upload a custom object, completed of its own image, to the graph api explorer.
I have written code for email verification on user registration using nodemailer in nodejs but it is working fine only when running on localhost,
once I put this on server it is not working.Instead of localhost:8080 I used the server IP address then also same problem.
The snippet is
var smtpTransport = nodemailer.createTransport("SMTP", {
service: "Gmail",
auth: {
user: "abc#gmail.com",
pass: "12345"
}
});
var rand, mailOptions, host, link;
app.get('/send', function (req, res) {
rand = Math.floor((Math.random() * 100) + 54);
hash = bcrypt.hashSync(rand, 8);
console.log("hash key " + hash);
host = req.get('host');
console.log("Host -" + host);
link = "http://" + req.get('host') + "/verify?id=" + hash;
mailOptions = {
to: req.query.to,
subject: "Verify your Email account",
html: "Hello,<br> Please Click on the link to verify your email.<br>Click here to verify"
}
global.recip = mailOptions.to;
console.log("recipt =" + recip)
console.log(mailOptions);
smtpTransport.sendMail(mailOptions, function (error, response) {
if (error) {
console.log(error);
res.end("error");
} else {
console.log("Message sent: " + response.message);
res.end("sent");
}
smtpTransport.close();
});
});
app.get('/verify', function (req, res) {
console.log(req.protocol + ":/" + req.get('host'));
console.log("rand " + hash);
console.log("id -" + req.query.id);
if ((req.protocol + "://" + req.get('host')) == ("http://" + host)) {
console.log("Domain is matched. Information is from Authentic email");
if (req.query.id == hash) {
console.log("email is verified");
res.end("<h1 style=margin-top:200px;margin-left:200px;>Email " + mailOptions.to + " is been Successfully verified <br><a href='/password'>Reset Password</a>");
} else {
console.log("email is not verified");
res.end("<h1 style=margin-top:200px;margin-left:200px;>Please enter your email again </h1>");
}
} else {
res.end("<h1>Request is from unknown source");
}
});
The page where user will enter the email id for verification.
$(document).ready(function () {
var from, to, subject, text;
$("#send_email").click(function () {
to = $("#to").val();
if (to == '') {
alert("Please enter a valid email");
} else {
$("#message").text("Sending E-mail...Please wait");
}
$.get("http://23.253.245.25/send", {
to: to
}, function (data) {
if (data == "sent") {
$("#message").empty().html("<h4><br> Email is been sent at " + to + " . Please check inbox !</h4>");
}
});
});
<div class="form-group">
<input type="text" id="to" placeholder="Enter E-mail which you want to verify" onblur="validateEmail(this);" required /><br>
<button id="send_email" style="margin-top:10px;">Send Email</button><br>
<span id="message"></span>
</div>
I had exactly the same issue before on my server. Here are steps to fix it:
Go to: https://www.google.com/settings/security/lesssecureapps to enable logging in from "Less secure apps" - What you've done
Ensure that your server was enabled if it's currently being blocked in the list: https://myaccount.google.com/security#activity
For me the error log was saying
534-5.7.14 <https-//accounts.google.com/ContinueSignIn ..... Please log in via your web browser and then try again....
I believed it told me to login to GMail from my server's browser! So I tried to use Lynx - a browser for terminal to login to GMail (You can also login from: https://accounts.google.com/login). Then... Woo Hoo!, it works!
Good luck!
You have to enable below settings of gmail account from which you want to send mails
https://www.google.com/settings/security/lesssecureapps
Hope it works :)
You can use APP PASSWORD, not required to enable less secure app at your security level.
App password can be created for your custom applications eg: My Custom App
Use the newly generated password as your Gmail Password in your password field.
Support Link: https://support.google.com/accounts/answer/185833?hl=en
I'm using the Facebook JavaScript API and have gone over their documatation and cannot find the answer to the following question.
After a user has granted your application specific permissions (in this case read_stream), how do you obtain that particular data? To be more specific I am using the following as part of my login process:
function login(){
alert("[fbCommon]" + ' > login');
FB.login(function(response) {
if (response.authResponse) {
//console.log('Welcome! Fetching your information.... ');
alert("[fbCommon]" + ' > login > ' + 'Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
//console.log('Good to see you, ' + response.name + '.');
alert("[fbCommon]" + ' > login > ' + 'Good to see you, ' + response.name + '.');
});
} else {
alert("[fbCommon]" + ' > login > ' + 'User cancelled login or did not fully authorize.');
//console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'read_stream'});
}
Thanks for your help.
If all you want is their stream/feed data, change the
FB.api('/me', function(response) {...})
to
FB.api('/me/feed', function(response) {...})
You can use the trusty Graph Explorer to check this