我正在尝试更新列表项(类型是“超链接”或“图片”)上的值。当执行GET请求时,数据返回正常,但是当我尝试创建一个项目或使用该值对它进行udpate时,结果如下:
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
"message": "A value without a type name was found and no expected type is available. When the model is specified, each value in the payload must have a type which can be either specified in the payload, explicitly by the caller or implicitly inferred from the parent value.",
"innerError": {
"request-id": "d12dfb12-a068-4621-9f27-d284e4635060",
"date": "2019-05-28T08:52:51"
}
}
}
POST / PATCH请求转到:
https://graph.microsoft.com/v1.0/sites/<siteid>/lists/<listid>/items/
并包含一个简单的JSON(对于PATCH):
{
"WebPage":
{
"Description": "Microsoft Graph",
"Url": "http://graph.microsoft.com"
}
}
知道我在做什么错吗?我尝试使用.NET SDK和Graph Explorer,但以相同的错误结束...
答案 0 :(得分:0)
要更新列表中的项目,您需要提供ID作为URI的一部分,它应如下所示:
func setUpFetchedResultsViewController() {
let fetchRequest: NSFetchRequest<FlickrImage> = FlickrImage.fetchRequest()
let sortDescriptor = NSSortDescriptor(key: "photo", ascending: true)
let predicate = NSPredicate(format: "locations == %@", location)
fetchRequest.predicate = predicate
fetchRequest.sortDescriptors = [sortDescriptor]
fetchResultController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: dataController.viewContext, sectionNameKeyPath: nil, cacheName: nil)
fetchResultController.delegate = self
do {
try fetchResultController.performFetch()
} catch {
print(error.localizedDescription)
}
checkForImages()
}
@objc func fetchNewItems() {
let imagesInFlickr = fetchResultController.fetchedObjects!
let indexPath = IndexPath(row: 0, section: 0)
for image in imagesInFlickr {
dataController.viewContext.delete(image)
photoCollection.deleteItems(at: [indexPath])
try? dataController.viewContext.save()
}
//The function below downloads new images and saves into core data.
downloadImageDetailsFromFlickr()
self.photoCollection.reloadData()
}
func checkForImages() {
if fetchResultController.fetchedObjects!.count == 0 {
downloadImageDetailsFromFlickr()
try? fetchResultController.performFetch()
photoCollection.reloadData()
} else {
try? fetchResultController.performFetch()
photoCollection.reloadData()
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath) as! collectionCell
let image = fetchResultController.object(at: indexPath)
if let cellImage = image.photo {
DispatchQueue.main.async {
cell.imageView.image = UIImage(data: cellImage)
}
}
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath) as! collectionCell
if cell.isSelected {
let alertVC = UIAlertController(title: .none, message: .none, preferredStyle: .actionSheet)
alertVC.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
alertVC.addAction(UIAlertAction(title: "Delete", style: .destructive, handler: { (_) in
let image = self.fetchResultController.object(at: indexPath)
self.dataController.viewContext.delete(image)
do {
try self.dataController.viewContext.save()
try self.fetchResultController.performFetch()
} catch {
print(error.localizedDescription)
}
DispatchQueue.main.async {
self.photoCollection.deleteItems(at: [indexPath])
self.photoCollection.reloadData()
}
}))
present(alertVC, animated: true, completion: nil)
}
}
您遇到的错误是尝试使用Graph无法与该集合协调的对象更新集合时返回的错误。