1
votes

Apparently it's a security issue, but the example downloaded from the website works correctly (ToDo), my application is simpler, does not work, because I really do not understand, I checked the libraries, the manifesto, code, everything seems to be correct. What am I doing wrong? I have an open question on this problem earlier, but now I think I can best describe the problem

Error : Unauthorized

Complete error: Error in activity com.microsoft.windowsazure.mobileservices.MobileServiceException: Error while processing request. at com.microsoft.windowsazure.mobileservices.MobileServiceConnection$1.onNext at com.microsoft.windowsazure.mobileservices.MobileServiceClient$4.handleRequest at com.microsoft.windowsazure.mobileservices.MobileServiceConnection.start at com.microsoft.windowsazure.mobileservices.RequestAsyncTask.doInBackground at com.microsoft.windowsazure.mobileservices.RequestAsyncTask.doInBackground at android.os.AsyncTask$2.call at java.util.concurrent.FutureTask$Sync.innerRun at java.util.concurrent.FutureTask.run at android.os.AsyncTask$SerialExecutor$1.run at java.util.concurrent.ThreadPoolExecutor.runWorker at java.util.concurrent.ThreadPoolExecutor$Worker.run at java.lang.Thread.run Caused by: com.microsoft.windowsazure.mobileservices.MobileServiceException: code":401,"error":"Error: Unauthorized"} at com.microsoft.windowsazure.mobileservices.MobileServiceConnection$1.onNext

My Code for download : https://skydrive.live.com/embed?cid=3CF3FC770FC59E9B&resid=3CF3FC770FC59E9B!1277&authkey=ADQMeBtUVTTIjtE%22

package com.bn7.rota;
import java.net.MalformedURLException;

import com.bn7.rota.Item;
import com.microsoft.windowsazure.mobileservices.*;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {
    private MobileServiceClient mClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
             mClient = new MobileServiceClient( 
                    "https://bn7.azure-mobile.net/", 
                    "hCzcrsFYhkGmxPvQDNxyqBXjZwjXlK99", 
                    this 
                    );
            Item item = new Item(); 
            item.IdPhone = "Awesome item"; 
            item.DateTimePhone = "2013/04/02 08:27:32"; 
            item.LatitudePhone = -43; 
            item.LongetudePhone = -23; 
            item.Active = false; 
            mClient.getTable(Item.class).insert(item, new TableOperationCallback<Item>() {
                 public void onCompleted(Item entity, Exception exception, ServiceFilterResponse response) { 
                    if (exception == null) { 
                         // Insert succeeded 
                                            } else { 
                         // Insert failed
                        Log.d("Insert failed", "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
                        Log.d("Insert failed", "Error in activity", exception);  
                        Log.d("Insert failed", "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
                    } 
                 } 
            });
        } catch (MalformedURLException e) {
            Log.d("MalformedURLException", e.toString());
        }
}


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}
package com.bn7.rota;

public class Item { 
    public int Id; 
    public String IdPhone;
    public String DateTimePhone;
    public double LatitudePhone;
    public double LongetudePhone;
    public boolean Active;
    }

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bn7.rota"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="17" />
        <uses-permission android:name="android.permission.INTERNET" />
        <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.bn7.rota.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
2

2 Answers

3
votes

The Unauthorized error you're getting indicates that you don't have permission to perform the operation on the table. If your operation's permissions (in the portal) are set to "Anybody with the Application Key", then you're sending over the incorrect application key. If it's set to "Only Authenticated Users", you'd need to be an authenticated user (with the Mobile Service) for it to work. If it's set to "Only Scripts and Admins" then you either have to send over your master key in the header or be accessing the table from a different script.

0
votes

Authentication / Authorization

Make sure Authentication/ Authorization is turned off!