Trying to download publicly accessible file from kinvey to android app
tried following code,
FileOutputStream fos = new FileOutputStream(videoName);
FileMetaData meta = new FileMetaData(videoName);
meta.setId(videoName);
kinveyClient.file().downloadWithTTL(meta.getId(), 1200000, fos, new DownloaderProgressListener() {
#Override
public void progressChanged(MediaHttpDownloader downloader) throws IOException {
Log.i("", "progress updated: " + downloader.getDownloadState());
final String state = new String(downloader.getDownloadState().toString());
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
//tProgress.setText((tProgress.getText() == null) ? state : tProgress.getText() + "\n" + state)
}
});
}
#Override
public void onSuccess(Void result) {
}
#Override
public void onFailure(Throwable error) {
}
});
getting event success but data is not being received. any idea how this will work??
getting error like this :
failure com.kinvey.java.core.KinveyJsonResponseException: InsufficientCredentials
The credentials used to authenticate this request are not authorized to run this operation. Please retry your request with appropriate credentials
According to the documentation, this is how you are supposed to use the value you get from getDownloadState() . In order to get the progress of your download, you need to first check the downloadState is equal to DOWNLOAD_IN_PROGRESS value, and then use the download.getProgress() method to get the progress, then you can use this to update the value on your progress slider, (you shouldn't be converting these values to string using the toString() method like you've done above.
public void progressChanged(MediaHttpDownloader downloader) throws IOException {
switch (downloader.getDownloadState()) {
case DOWNLOAD_IN_PROGRESS:
//Download in progress
//Download percentage: + downloader.getProgress()
break;
case DOWNLOAD_COMPLETE:
//Download Completed!
break;
}
}
Code taken from documentation here
Nayana,
You might be getting this error because user does not have permission to access that file. You can try following to solve your issue:
If you make the file publicly readable, all authenticated users will be able to access that particular file.
You can make the file accessible by adding read/write permissions for
few users in ACL.
Also check the documentation for Access Control List:
http://devcenter.kinvey.com/rest/guides/security#entityanduserpermissions
Thanks,
Pranav
Kinvey Support
Related
File file =
HyperLog.getDeviceLogsInFile(this);
HyperLog.setURL("url");
HyperLog.pushLogs(this, file.getAbsolutePath(), false, new HLCallback() {
#Override
public void onSuccess(#NonNull Object response) {
Log.d("HYPERLOG", "onSuccess: called");
}
#Override
public void onError(#NonNull HLErrorResponse HLErrorResponse) {
Log.d("HYPERLOG", "onError: called");
MiscUtilities.sendErrorReportToCrashAnalytics("onErrorCalled"+HLErrorResponse.getErrorCode());
}
});`
and I am initializing the hyper logs in my Base Application like this
HyperLog.initialize(this);
HyperLog.setLogLevel(Log.VERBOSE);
can anyone tell me what's wrong I am doing here ??
Due to below statement logs are already written to file so after this statement if you call pushLogs() API then no logs will be available to push.
File file = HyperLog.getDeviceLogsInFile(this);
Otherwise call File file = HyperLog.getDeviceLogsInFile(this,false); so on file write it will not delete logs from DB and call to pushLogs() will push logs to server.
I have a standalone Java application that uses a OneDrive Java API I found on github. Everything works nicely.
So I already have a clientid, a client secret, an authorization code and a refresh token which work flawlessly
Now I wanted to switch over to Android, but I wasn't successfull in using the same Java API. That's why I wanted to move to the official OneDrive Android SDK provided by Microsoft.
Everything seems to be different there. I tried the following, using my already known clientid
final Activity me = this;
final MSAAuthenticator msaAuthenticator = new MSAAuthenticator() {
#Override
public String getClientId() {
return clientid;
}
#Override
public String[] getScopes() {
return new String[] { "onedrive.appfolder" };
}
};
final IClientConfig oneDriveConfig = DefaultClientConfig.createWithAuthenticator(
msaAuthenticator);
final IOneDriveClient oneDriveClient = new OneDriveClient.Builder()
.fromConfig(oneDriveConfig)
.loginAndBuildClient(me);
oneDriveClient
.getDrive()
.buildRequest()
.get(new ICallback<Drive>() {
#Override
public void success(final Drive result) {
final String msg = "Found Drive " + result.id;
Toast.makeText(me, msg, Toast.LENGTH_SHORT)
.show();
}
#Override
public void failure(ClientException ex) {
final String msg = "Error";
Toast.makeText(me, msg, Toast.LENGTH_SHORT)
.show();
}
});
It ends up in a seemingly endless loop while executing the line .loginAndBuildClient(me)
In logcat I see that it suppressed an Exception
07-13 12:32:17.082 28175-28271/org.xxxxxxx.xxxxxxxxx E/MSAAuthenticator$5[onAuthComplete] - 314:
Failed silent login, interactive login required
com.onedrive.sdk.authentication.ClientAuthenticatorException: Failed silent login, interactive login required
at com.onedrive.sdk.authentication.MSAAuthenticator$5.onAuthComplete(MSAAuthenticator.java:312)
There are also some info messages:
07-13 12:32:17.079 28175-28271/org.xxxxxxx.xxxxxxxxx I/LiveAuthClient:
No refresh token available, sorry!
07-13 12:32:17.079 28175-28271/org.xxxxxxx.xxxxxxxxx I/LiveAuthClient:
All tokens expired, you need to call login() to initiate interactive logon
Obviously it somehow wants to perform an interactive login and fails terribly.
What I don't understand: I already have a perfectly valid refresh token which I want to reuse, but I did not find a way to do it in the MS OneDrive SDK.
Can someone help me here?
This post is a little old, but i wanted to share my solution to help others.
Instead of using this method "loginAndBuildClient" with only the Activity parameter, like this :
final IOneDriveClient oneDriveClient = new OneDriveClient.Builder()
.fromConfig(oneDriveConfig)
.loginAndBuildClient(me);
Declare a global OneDriveClient:
private IOneDriveClient mOneDriveClient;
Then use the "loginAndBuildClient" method with the Callback parameter. And assign your OneDriveClient in the "success" method :
new OneDriveClient.Builder()
.fromConfig(DefaultClientConfig.createWithAuthenticator(msaAuthenticator))
.loginAndBuildClient(MainActivity.this, new ICallback<IOneDriveClient>() {
#Override
public void success(IOneDriveClient iOneDriveClient) {
mOneDriveClient = iOneDriveClient;
}
#Override
public void failure(ClientException ex) {
mOneDriveClient = null;
}
});
I managed to implement access to the OneDrive API manually (without using the SDK) and it worked
Turns out I "only" forgot to set INTERNET permission for the app. Really strange that it caused my app to fail silently.
I'm trying to implement Facebook sharing in my game using Unity 3D + Facebook Unity SDK. But when I tried testing to post to my wall, this error shows up: "We are Sorry, this post is no longer available. It may have been removed." Can anybody help me? Thanks in advance.
BTW, here's my code:
using UnityEngine;
using System.Collections;
public class FacebookController : MonoBehaviour {
public bool isUsingFacebook = true; //Are we using Facebook SDK? This variable is only
//Feed parameters.
private string link = "market://details?id=com.LaserCookie.Queue"; //The link that will show the user the game's google play store address
private string linkName = "Queue"; //The link name
private string linkCaption = "Wow this game is great! 10/10 must play!"; // The caption of the link
private string linkDescription = "I achieved the score of " + PlayerController.instance.score.ToString() + "! Try to beat me if you can!"; //The description of the link
private string picture = "http://www.drycreekequestriancenter.com/testImage.jpeg"; //This is the image / game icon for the link. For now, it's shamelessly got from a random source. Thank you, random citizen...
void Awake()
{
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
//Init FB
private void Init()
{
if (!FB.IsInitialized)
{
FB.Init(OnInitComplete, OnHideUnity);
}
}
//Callback that will be called when the initialization is completed
private void OnInitComplete()
{
Debug.Log("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
//Check if we are logged in.
//If not, we will log in.
//If we are, post status.
if (!FB.IsLoggedIn)
{
LoginWithPublish();
}
else
{
PostImpl();
}
}
//Callback that will be called when the game is shown / not
private void OnHideUnity(bool isGameShown)
{
Debug.Log("Is game showing? " + isGameShown);
}
//Post to Facebook. This is the only exposed method because we only use this to post to Facebook.
//The initialization and login will be called when needed.
//It will first detect whether or not we have been initialized. And will init if we haven't.
//Then it will check whether or not we have been logged in with publish. And will log in if not.
public void PostToFacebook()
{
//Are we using facebook SDK?
if (isUsingFacebook)
{
if (!FB.IsInitialized) //Check for initialization
{
Init();
}
else if (!FB.IsLoggedIn) //Check for login
{
LoginWithPublish();
}
else //Post if we are already initia;ized and logged in
{
PostImpl();
}
}
}
//The true implementation of the posting
private void PostImpl()
{
FB.Feed("",link, linkName,linkCaption,linkDescription,picture);
}
//Login to Facebook with publish
private void LoginWithPublish()
{
// It is generally good behavior to split asking for read and publish
// permissions rather than ask for them all at once.
//
// In your own game, consider postponing this call until the moment
// you actually need it.
FB.Login("publish_actions", LoginCallback);
}
//Login callback
void LoginCallback(FBResult result)
{
if (result.Error != null)
{
Debug.Log( "Error Response:\n" + result.Error );
//TODO: Retry login if we have error? Or do we display a pop up?
}
else if (!FB.IsLoggedIn)
{
Debug.Log( "Login cancelled by Player" );
//TODO: Do we display a pop up?
}
else
{
Debug.Log( "Login was successful!" );
PostImpl();
}
}
}
You need to add Key Hash for FB application.
Go to My Apps, select you application, open Setting tab, add platform for android, and add you key hash.
check this link out
Setting a Release Key Hash
I've fixed the issue. It turns out it's because I used my still in development google store address as the link. I thought it would be automatically recognized regardless of my app is live or not. Thank you anyway. :)
I am using Codenameone and ZXing to read a QRCode. When I call the Scanner, my mobile opens the QRCode reader application and I get to read the QRCode except that when android takes me back to my app it goes through init then start statuses. Which moves me back to the login form of my application instead of continuing filling the form that I was in.
Any help on what to do to stay in the same form? Is there something I'm doing wrong? Thanks in advance.
EverproX.addMessage("Before Scan\n");
CodeScanner.getInstance().scanQRCode(new ScanResult() {
public void scanCompleted(String contents, String formatName, byte[] rawBytes) {
EverproX.addMessage("Scan Completed "+contents);
}
public void scanCanceled() {
EverproX.addMessage("Scan Cancelled");
}
public void scanError(int errorCode, String message) {
EverproX.addMessage("Scan Error "+errorCode+" "+message);
}
});
EverproX can be seen as a log class.
By analyzing our log we can say that as soon as we call the CodeScanner.getInstance().scanQRCode() the application is called for 'Destroy'. Then after the scanning is done it goes again through the init and start. It never goes into the scanComplete scanCanceled or scanError Callbacks.
Is it normal that the App is destroyed upon call of CodeScanner? Many thanks.
Inside your codenameone project, you should find a class named (for example MyApp.java) based on your app's name, modify the code to read something like similar to this:
public class MyApp {
private Form current;
public void init(Object context) {
// Pro users - uncomment this code to get crash reports sent to you automatically
Display.getInstance().addEdtErrorHandler(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
evt.consume();
Log.p("Exception in AppName version " + Display.getInstance().getProperty("AppVersion", "Unknown"));
Log.p("OS " + Display.getInstance().getPlatformName());
Log.p("Error " + evt.getSource());
Log.p("Current Form " + Display.getInstance().getCurrent().getName());
Log.e((Throwable) evt.getSource());
Log.sendLog();
}
});
}
public void start() {
if (current != null) {
current.show();
return;
}
new StateMachine("/theme");
}
public void stop() {
current = Display.getInstance().getCurrent();
}
public void destroy() {
current = null;
}
}
I have an interesting problem that I've never run into in programming before. I have an onClickListener that does a lot of username and password checks (makes sure the username is proper length, not taken, etc). I'm using MobDB, and I was using a conditional statement that would return a row if the username already existed. The problem is that the Listener skips the DB and goes to the final check that, if everything works, posts a new username and password to my DB. How can I make it wait for a response from the DB before skipping to the last check?
Here is the relevant code:
usernamecheck3 = true;
MobDB.getInstance().execute(APP_KEY, null, rd, null, false, new MobDBResponseListener() {
#Override public void mobDBSuccessResponse() {
usernamecheck3 = false;
Log.e("mobdbSuccess:", "success");
}
#Override public void mobDBResponse(Vector<HashMap<String, Object[]>> row) {
}
#Override public void mobDBResponse(String jsonObj) {
/*Log.e("mobdbSuccess:", "jsonObj");
Log.e("mobdbSuccess:", jsonObj);
JSONObject mainObject;
try {
mainObject = new JSONObject(jsonObj);
// need to parse the json object.
} catch (JSONException e1) {
e1.printStackTrace();
} */
}
#Override public void mobDBFileResponse(String fileName, byte[] fileData) {
//get file name with extension and file byte array
}
#Override public void mobDBErrorResponse(Integer errValue, String errMsg) {
usernamecheck3 = false;
Log.e("doesnt", "work");
}
});
if(usernamecheck3 == false){
Toast.makeText(getApplicationContext(), "Username is taken, please choose another", Toast.LENGTH_SHORT).show();
}
Basically the check always returns true, and then logcat will say mobdbSuccess: success, which should have set the Bool to false.
Thanks.
MobDBResponseListener is executing on a different thread. What happens here is that the processing is split, while a thread is doing the query, the main thread on which you added the listener, skips right ahead to the validation. Your best bet is to place the validation inside the MobDBResponseListener, on the mobDBResponse method.
Try to debug your code and calls, the Listener may be using an async task. If so, you may do anything you please from the response method, as it will be executing in the main thread again. Otherwise, you should look at solutions that handle threaded execution like Handlers