I'm trying to send an email using native.showPopup, but the email is never sent, below is the code:
function scene:createScene( event )
function sendMail()
local options =
{
to = "yourname#youremail.com",
subject = "Game Result",
isBodyHtml = true,
body = "<html><body>Play Time: <b>10</b> <br> Score: <b>1</b></body></html>"
}
native.showPopup("mail", options)
end
-- add some button to send mail
submitBtn = widget.newButton{
defaultFile="assets/submit.png",
over="assets/submit.png",
width=display.contentWidth/2, height=display.contentHeight/6,
onPress = sendMail
}
end
scene:addEventListener( "createScene", scene )
return scene
and this is the build.settings:
settings = {
android =
{
versionCode = "11",
usesPermissions =
{
"android.permission.INTERNET",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.ACCESS_FINE_LOCATION",
"android.permission.ACCESS_COARSE_LOCATION",
}
},
}
I've tried in simulator and on my phone, but nothing is working. Can anyone help me?
i dont know why, but i just add some validation and now its work..
here the revision code i made:
function sendMail()
local options =
{
to = "yourname#youremail.com",
subject = "Game Result",
isBodyHtml = true,
body = "<html><body>Play Time: <b>10</b> <br> Score: <b>1</b></body></html>"
}
-- add some validation
-- and this is revision code
local mailSend = native.showPopup("mail", options)
if not mailSend then
native.showAlert( "Alert!", "Mail cannot be send.", { "OK" })
end
end
thx
Related
How to get the following list from the Instagram account using the access token
I tried everything but not work.
here some API link which I tried before but none of them work.
I tried this one https://www.instagram.com/urvish_._/?__a=1
also this one
I tried but nothing can help me.
You can get the following (or also follower) list using the code below. Steps:
Make sure you're logged in on instagram.com
Open the API link: https://www.instagram.com/urvish_._/?__a=1 (your target username here is urvish_._)
Open the browser console: normally Ctrl+Shift+J on Windows/Linux or ⌘+Option+J on Mac
Paste this code and press Enter:
const GRAPHQL_MAX_PER_PAGE = 50;
async function getList() {
let pageLimit = 200; // from my testing
let baseInfo = JSON.parse(document.getElementsByTagName('body')[0].innerText);
let userId = baseInfo.graphql.user.id;
let config = { user_edge: 'edge_follow', query_hash: 'd04b0a864b4b54837c0d870b0e77e076', total_count: baseInfo.graphql.user.edge_follow.count };
// for followers instead of followings:
// { user_edge: 'edge_followed_by', query_hash: 'c76146de99bb02f6415203be841dd25a', total_count: baseInfo.graphql.user.edge_followed_by.count }
let after = null, hasNext = true, thisList = [];
for (pageCount = 1; hasNext && (pageCount <= pageLimit); ++pageCount) {
try {
let response = await fetch(`https://www.instagram.com/graphql/query/?query_hash=${config.query_hash}&variables=` + encodeURIComponent(JSON.stringify({
id: userId, include_reel: true, fetch_mutual: true, first: GRAPHQL_MAX_PER_PAGE, after: after
})));
if (!response.ok) {
console.warn(`Failed at page number ${pageCount.toLocaleString()}. HTTP status ${response.status}: ${response.statusText}.`);
break;
}
try {
response = await response.json();
} catch (error) {
console.error(`You may need to verify your account. Stopping. Failed at page number ${pageCount.toLocaleString()}.`, error);
break;
}
hasNext = response.data.user[config.user_edge].page_info.has_next_page
after = response.data.user[config.user_edge].page_info.end_cursor
thisList = thisList.concat(response.data.user[config.user_edge].edges.map(({ node }) => {
return {
id: node.id,
username: node.username,
full_name: node.full_name,
profile_pic_url: node.profile_pic_url,
};
}));
} catch (error) {
console.warn(`Error at page number ${pageCount.toLocaleString()}:`, error);
}
console.log(`${thisList.length.toLocaleString()} of ${config.total_count.toLocaleString()} fetched so far`);
}
console.info(`${thisList.length.toLocaleString()} fetched.`);
console.log(thisList);
}
getList()
Browser console showing a fetched list after code execution
In the code I've set the page limit to 200 so you can get up to 10,000 of your followings.
PS: For a way to visualise your lists and get more details, you can try Instagram Lists, a tool I made.
I'm making a simple app for getting personal information from the user and number of images to send them through backend mail API with a one click of a button. So far, I can get and send the FormData through mail but I couldn't figure it out the how to send an array of images.
I have tried several API's but "Mailer" seems to best for SMTP. As for the code, I tried to convert the "File" class to String or List but none of those have worked for me. I'am not a intermediate coder so be kind with me :)
That's how I get the images using "image_picker"
File _image1;
Future getImage1Camera() async {
var image1 = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
_image1 = image1;
});
}
And the "mailer" code
void _mailer() async{
if(!_formKey.currentState.validate()){
return;
}else{
_formKey.currentState.save();
}
String gmailUsername = '**';
String gmailPassword = '**';
final smtpServer = gmail(gmailUsername, gmailPassword);
final ceSendMail = Message()
..from = Address(gmailUsername, '')
..recipients.add('recipent')
..subject = 'Test'
..text = 'Plain Text'
..html = ''//Form Data
..attachments.add(_image1);//TODO: User input images
try {
final sendReport = await send(cekSendMail, smtpServer);
print('Message sent: ' + sendReport.toString());
} on MailerException catch (e) {
print('Message not sent.');
for (var p in e.problems) {
print('Problem: ${p.code}: ${p.msg}');
}
}
// Create a smtp client that will persist the connection
var connection = PersistentConnection(smtpServer);
// Send the message
await connection.send(cekSendMail);
// close the connection
await connection.close();
}
This is the error I get and whatever I try it's always the "type" error.
The argument type 'File' can't be assigned to the parameter type 'Attachment'.
So, how can I get multiple image files from user and send through mail API?
You need to wrap your file with FileAttachment
..attachments.add(FileAttachment(_image1))
In my ionic app I have a POST request to do login. This works fine on an iPhone but when I test the app on an Android phone the server returns a 404 Not Found error.
My code for making the HTTP request looks like this:
loginUser: function(email,password) {
var em = email.replace(/\s/g,'');
var pw = password.replace(/\s/g,'');
var url = apiDomain + '/api/v1/user/login/';
if (em && pw) {
return $http.post(url, {
auth: {
email: em,
password: pw
}
}).then(function successCallback(response) {
alert('login success. response = '+JSON.stringify(response));
return response;
}, function errorCallback(response) {
alert('login fail. response = '+JSON.stringify(response));
return -1;
});
}
},
Can anyone think of a reason why this would work on an iPhone but not on an Android phone?
The text shown by the alert() in the errorCallback is:
login fail. response = {
"data":"",
"status":404,
"config":{
"method":"POST",
"transformRequest":[null],
"url":"http://cues-server-dev.elasticbeanstalk.com/api/v1/user/login/",
"data":{
"auth":"{
"email":"aa#aa.aa",
"password":"alcohol"}},
"headers":{
"Accept":"application/json,text,plain,*/*",
"Content-Type":"application/json;charset=utf-8"}},
"statusText":"Not Found"}
I am at a loss to understand why this works on an iPhone but not an Android phone.
It may be to do with the URL prefix. Have you tried using:
apiDomain = #"https://cues-server-dev.elasticbeanstalk.com"
or
apiDomain = #"http://www.cues-server-dev.elasticbeanstalk.com"
or some other variant.
I need help to solve this problem: I want to post on FB a save screen from my app (I got save screen by using display.save function). Everything works fine on Android while on my iPad it crashes! Please find the function code below:
local function postonFB( event)
display.save( tab3fields, { filename="ticket.jpg", baseDir=system.DocumentsDirectory, isFullResolution=true, backgroundColor={0, 0, 0, 0} } )
local fbAppID = "4531113981XXXXX"
local function fbListener( event )
if event.phase == "login" then
local attachment = {
message="I am a champion!",
source= {baseDir=system.DocumentsDirectory, filename="ticket.jpg", type="image"}
}
facebook.request("me/photos", "POST", attachment)
native.showAlert("Facebook", "Submitted!")
end
end
-- photo uploading requires the "publish_actions" permission
facebook.login( fbAppID, fbListener, { "publish_actions" } )
end
Please help, I am getting crazy to understand what's wrong!
Thanks a lot. Ubaldo
here is my facebook sharing code:
baseDir = system.DocumentsDirectory
display.save( group , "screenshot.png", system.DocumentsDirectory )
local facebook = require "facebook"
local fbAppID = "898209XXXXXXXXX"
function onLoginSuccess()
attachment = {
message = "i got ".. score .. " blablabla",
source = { baseDir=system.DocumentsDirectory, filename="screenshot.png", type="image" }
}
facebook.request( "me/photos", "POST", attachment )
end
function fbListener( event )
if event.isError then
native.showAlert( "ERROR", event.response, { "OK" } )
else
if event.type == "session" and event.phase == "login" then
onLoginSuccess()
elseif event.type == "request" then
print("upload done")
end
end
end
facebook.login( fbAppID, fbListener, { "publish_stream", "publish_actions" } )
ps do you have this in you build.settings?
plugins =
{
["facebook"] =
{
publisherId = "com.coronalabs"
},
},
I have two apps, one is a trial version the other the full version of a game, both made with adobe air. While saving data via the sharedobjects solution is no problem, I would like to use "one" savegame for both appsm, so users can keep their progress when upgrading to the full version. I tried around a little. But code like e.g. ...:
SharedObject.getLocal("myApp","/");
... doesnt work. So the question is, is there a way to have two Air apps using the same shared object? Or maybe if not using, at least "read" the shared object of another Air app?
Thanks in advance,
ANB_Seth
The answer is yes, I actually made a game transfer system for iOS and Android via network connection and 6 digit hash the user has to enter in the newly installed app to fetch the SO from the server. You could do this with a simple file stored locally on the SD card or other local storage device.
/**
* send this user's current save data to the server
*/
public function send():void{
var ba:ByteArray = new ByteArray();
// Main.sv.user - is the registerClassAlias object we write/read locally via SharedObject
ba.writeObject(Main.sv.user);
var name:String = Crypto.hash("Random Secrect Salt - typically user score, name, etc.");
// create 6 digit hash
var key:String = Crypto.hash(name).slice(0, 6).toUpperCase();
var request:URLRequest = new URLRequest ( 'https://sharedobject.com/transfer/save/name/'+name+'/key/'+key );
var loader: URLLoader = new URLLoader();
request.contentType = 'application/octet-stream';
request.method = URLRequestMethod.POST;
request.data = ba;
loader.addEventListener(IOErrorEvent.IO_ERROR, function (evt:Event) {
trace("error - network");
onSaveRestoreEvent(1);
});
loader.addEventListener(Event.COMPLETE, function (evt:Event) {
addChild(new BaseDialog("Save Sent To Server", "Your data has been sent to the server. To get this data back from the server " +
"you will need your secret key. Please write this six digit key down:\n"+name));
});
loader.load( request );
}
/**
* create a GET SO dialog
*/
public function receive():void{
var text:Sprite = new Sprite();
var textInput:TextInput = new TextInput();
textInput.width = Constants.SCREEN_WIDTH-100;
textInput.y = -50;
text.addChild(textInput);
var dialog:BaseDialog = new BaseDialog("Enter Secret Save Key", "Please enter your six digit secret save key in the field below, then press \"Get\".\n\n",
"Get", function():void{
text.removeChildren();
var url:String = "https://sharedobject.com/transfer/get/name/"+textInput.text; //servlet url
var request:URLRequest = new URLRequest(url);
//get rid of the cache issue:
var urlVariables:URLVariables = new URLVariables();
urlVariables.nocache = new Date().getTime();
request.data = urlVariables;
request.method = URLRequestMethod.GET;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, function (evt:Event) {
var loader:URLLoader = URLLoader(evt.target);
var bytes:ByteArray = loader.data as ByteArray;
bytes.position = 0;
if(bytes.length <= 10 || !(bytes.readObject() is User)){
onSaveRestoreEvent(2);
}else{
try{
bytes.position = 0;
Main.sv.user = (bytes.readObject() as User);
Main.sv.save();
onSaveRestoreEvent(0);
}
catch( e : EOFError ){
onSaveRestoreEvent(3);
}
}
});
loader.addEventListener(IOErrorEvent.IO_ERROR, function (evt:Event) {
trace("error - network");
onSaveRestoreEvent(1);
});
loader.load(request);
},
"Close", function():void{text.removeChildren();}, null, null, text);
dispatchEvent(new CreateBaseDialogEvent(dialog));
}
/**
* called after the restore save system is done
* #param prompt int [0 = complete][1 = error network][2 = error key][3 = error EOF]
*/
private function onSaveRestoreEvent(prompt:int):void{
var dialog:BaseDialog;
if(prompt == 0){
dialog = new BaseDialog("Restore Complete!", "All save data has been restored.");
}else if(prompt == 1){
dialog = new BaseDialog("Network Error!", "Please seek an internet connection and try again.");
}else if(prompt == 2){
dialog = new BaseDialog("Invalid Secret Key!", "The key you've entered seems to be invalid, or the save data has expired on the server. " +
"Data only lasts on the server for 24 hours.");
}else{
dialog = new BaseDialog("Error!", "There was an issue getting the file from the server. Please try the transfer again.");
}
dispatchEvent(new CreateBaseDialogEvent(dialog));
}