2016-10-07 3 views
2

Mit Outlook Ich versuche, Ereignis zu erstellen, Wenn ich Anfrage mit POSTMAN senden funktioniert es gut, Aber der gleiche Code in Angularjs ist nicht wotking. was ist falsch mit Code. Bitte helfen.Outlook Rest Anrufformular angularjs

$scope.createEvents = function(){ 
    var url = "https://outlook.office.com/api/v2.0/$metadata#Me/Calendars"; 
    //var url = "https://outlook.office.com/api/v2.0/$metadata#me/Calendars"; 

    var add_events = { 
       "Subject": "Discuss the Calendar REST API", 
       "Body": { 
       "ContentType": "HTML", 
       "Content": "I think it will meet our requirements!" 
       }, 
       "Start": { 
        "DateTime": "2016-10-10T18:00:00", 
        "TimeZone": "Pacific Standard Time" 
       }, 
       "End": { 
        "DateTime": "2016-10-10T19:00:00", 
        "TimeZone": "Pacific Standard Time" 
       }, 
       "Attendees": [ 
       { 
        "EmailAddress": { 
        "Address": "[email protected]", 
        "Name": "Sathish Gopi" 
        }, 
        "Type": "Required" 
       } 
       ] 
      }; 
    $http({ 
     method: 'POST', 
     url: url, 
     headers:{ 
      'Authorization':'Bearer '+$scope.token, 
      'Content-Type': "application/json", 
      'Accept': 'application/json;odata.metadata=minimal', 
      'Access-Control-Allow-Origin':'*'    
     },   
     data: add_events 
    }).Succes(function (response) { 
     alert("Saved") 
    }); 

Ich bekomme. Fehler beim Laden der Ressource: Der Server hat mit dem Status 406 (Nicht akzeptabel) geantwortet. Zur Lösung dieses Problems ich diesen Code bin jetzt mit

$scope.createEvents = function(){ 
var url = "https://outlook.office.com/api/v2.0/$metadata#Me/Calendars"; 
//var url = "https://outlook.office.com/api/v2.0/$metadata#me/Calendars"; 

var add_events = { 
      "Subject": "Discuss the Calendar REST API", 
      "Body": { 
      "ContentType": "HTML", 
      "Content": "I think it will meet our requirements!" 
      }, 
      "Start": { 
       "DateTime": "2016-10-10T18:00:00", 
       "TimeZone": "Pacific Standard Time" 
      }, 
      "End": { 
       "DateTime": "2016-10-10T19:00:00", 
       "TimeZone": "Pacific Standard Time" 
      }, 
      "Attendees": [ 
      { 
       "EmailAddress": { 
       "Address": "[email protected]", 
       "Name": "Sathish Gopi" 
       }, 
       "Type": "Required" 
      } 
      ] 
     }; 
$http({ 
    method: 'JSONP', 
    url: url, 
    headers:{ 
     'Authorization':'Bearer '+$scope.token, 
     'Content-Type': "application/json", 
     'Accept': 'application/json;odata.metadata=minimal', 
     'Access-Control-Allow-Origin':'*'    
    },   
    data: add_events 
}).Succes(function (response) { 
    alert("Saved") 
}); 

nach der Verwendung von JSONP als Methode erhalte ich diesen Fehler

Uncaught Syntaxerror: unerwartete Token <

+0

Haben Sie die Anforderungsdetails in der Registerkarte Netzwerk in Entwicklungstools überprüft? –

+0

Ressource konnte nicht geladen werden: Der Server reagierte mit einem Status von 406 (Not Acceptable) –

Antwort

0

406 nicht akzeptabel ist definiert als die folgende:

The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

siehe restapitutorial: http status codes

Sie die folgenden Accept-Header senden:

'Accept': 'application/json;odata.metadata=minimal' 

Der Server sagt, es mit diesem Inhaltstyp nicht produzieren kann. Wenn Sie es mit Postboten laufen lassen, schauen Sie sich an, welche Header Sie dort akzeptieren.

Zum zweiten Versuch: jsonp ist keine http-Methode/Verb (GET, PUT, POST, DELETE, PATCH). Ich bin kein angularjs Experte, aber für den Fall, dass Sie Jsonp benötigen, gibt es eine method, die Sie anrufen können.

JSONP ist eine ziemlich spezifische (und etwas problematische) Technik. Solange du das kannst, versuche es zu vermeiden.

+0

Danke, das gleiche Stück Code statt in js schreiben in Java schreibt es funktioniert gut. –

0

Ich weiß, ihr eine alte Post, ich habe das gleiche Problem hat, und das ist die Lösung, wenn jemand in das gleiche Problem fällt, Sie https://graph.microsoft.com/v1.0/me/calendar/events als URL

Exemple Code getestet verwenden sollten:

var url = "https://graph.microsoft.com/v1.0/me/calendar/events"; 

    var add_events = { 
              "Subject": "Title", 
              "Body": { 
              "ContentType": "HTML", 
              "Content": " Exemple" 
              }, 
              "Start": { 
               "DateTime": "2010-05-17T18:00:00", 
               "TimeZone": "UTC" 
              }, 
              "End": { 
               "DateTime": "2010-05-17T19:00:00", 
               "TimeZone": "UTC" 
              } 
             }; 
    $http({ 
      method: 'POST', 
      url: url, 
      headers:{ 
              'Authorization':'Bearer '+localStorage.getItem('Your Token here'), 
              'Content-Type':'application/json', 
              'Accept': 'application/json;odata.metadata=minimal', 
              'Access-Control-Allow-Origin':'*', 
              'token_type':'Bearer' 
             }, 
             data: add_events 
            }).then(function successCallback(response) { 

             console.log(response); 

             }, function errorCallback(response) { 

             localStorage.setItem('etat_mytoken', 0); 
             $window.location.href = url_base+'/'+url_base_v+'/app/assets/views/token.html'; 


             }); 
Verwandte Themen