- Could you show us the complete code with which we can try to reproduce the issue on our end?
- Is the issue on the same machine where it works in MATLAB but not in standalone application? Or is this on a different machine?
- How are ""accesstoken" and "message" passed? Is there any difference in the way these values are passed to the function in MATLAB and standalone? Is the accesstoken same in both the cases?
- Could you show us the complete error message?
Program works in MATLAB, but doesn't work after compiling as a standalone application
41 views (last 30 days)
Show older comments
Daniel LaCroix
on 19 Aug 2015
Commented: Danial DanialB
on 22 Jan 2019
I'm trying to use MATLAB compiler to make a program a standalone application. The program runs fine in MATLAB, but gives an error as a standalone application. I don't think the problem is with missing files or mismatched versions of the compiler and runtime.
The compiled program runs at first, the gives an error and tells me on what line it occurred. The problem is with the webwrite command. I'm using it to send an email through the Gmail API. This requires me to change the MediaType in weboptions from the default of 'application/x-www-form-urlencoded' to 'application/json'. When I include the email message in the webwrite command in a structure, it is converted to a JSON object and posted to the specified URL. This works in MATLAB, but the compiled program gives an error that says 'The input cannot be converted to JSON'. The lines of code pertaining to this are:
options = weboptions('MediaType','application/json','RequestMethod','post');
data=struct('raw',messageb64); %messageb64 is the email encoded in base64
webwrite(strcat('https://www.googleapis.com/gmail/v1/users/me/messages/send?access_token=',accesstoken),data,options)
I'm guessing the input mentioned in the error is the structure, but there is no problem encoding it as JSON in MATLAB, so I don't know what the problem is.
EDIT: I have looked at the FAQ sites and tried some of their suggestions. I confirmed that my versions of MATLAB and runtime match. I have also confirmed that the functions I created are all there. I have successfully compiled other programs; it really seems to be an issue with the webwrite command.
In response to Dasharath's questions:
1. I don't want to post the full code. There are 6 functions it depends on, which would be a pain to post. More importantly, because I am working with the gmail api, providing my full code would allow anybody to send email from my account. I'm using a test email, but I still don't want to do this. I know this makes it way harder for people to help, and I appreciate your efforts. I can post segments of the code if needed. I might write a version that will allow people to use their own emails. Let me know if that would be helpful.
2. I am doing all the coding and testing on the same machine. I just got back to college, so I might test it out on the school computers.
3. Access token is part of the URL the webwrite command posts to. It is a code that the Gmail API uses for authentication, and is only valid for an hour before needing to be refreshed, so that is why it is a variable and not just typed in like the rest of the URL. The message is passed in the structure named "data". I'm not entirely sure how it works, as I relied largely on trial and error, but the MATLAB documentation says it is converted to a JSON object.
4. The exact text of the error is "The input cannot be converted to JSON. Error in => prettyaurora.m at line 27."
Thanks for your help.
1 Comment
Dasharath Gulvady
on 21 Aug 2015
Accepted Answer
Daniel LaCroix
on 7 Sep 2015
3 Comments
Image Analyst
on 20 Apr 2018
Are you saying his solution of "I ended up contacting MathWorks directly about this." didn't work? Well if even the Mathworks can't figure it out, then I guess you're out of luck.
Danial DanialB
on 22 Jan 2019
Thank you so much!!!
Had same problem but with sym function and i fixed it by adding MATLABROOT\toolbox\symbolic folder.
More Answers (2)
Walter Roberson
on 23 Aug 2015
You may wish to experiment with http://www.mathworks.com/matlabcentral/fileexchange/45238-jsonrpc2--a-set-of-classes-to-encode-decode-json-rpc-messages or http://www.mathworks.com/matlabcentral/fileexchange/33381-jsonlab--a-toolbox-to-encode-decode-json-files-in-matlab-octave -- not necessarily to do the heavy work but to help you debug what is going on, since it would be possible to add debugging and tracing into those routines as needed to figure out why you cannot encode.
See Also
Categories
Find more on JSON Format in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!