Route exchange online public folder hierarchy requests failed with "Expected an item Id but received a folder Id" - exchangewebservices

Description: We are having the technical difficulties to route the public folder hierarchy if there is a Journal folder, and we are thinking the workaround to use grapy API to do this, but didn't find the information to use Graph API to access the public folder, anyone can share more information would be appreciated.
Environment: Exchange online public folder. And there is one journal folder and one sub folder under the journal folder.
Method: Folder.FindFolders EWS API to route the public folder hierarchy.
Exception: error code: ErrorCannotUseFolderIdForItemId, error: Microsoft.Exchange.WebServices.Data.ServiceResponseException: Expected an item Id but received a folder Id.
Following is the sample code:
public static void GetPublicFolders(Folder parentFolder, int pageSize, int offset, string parentFolderPath)
{
try
{
FindFoldersResults result;
do
{
FolderView folderView = new FolderView(pageSize, offset);
folderView.Traversal = FolderTraversal.Shallow;
result = parentFolder.FindFolders(folderView);
foreach (Folder folder in result)
{
var path = parentFolderPath + #"\" + folder.DisplayName;
System.Console.WriteLine(path);
GetPublicFolders(folder, pageSize, 0, path);
}
offset += pageSize;
}
while (result.MoreAvailable);
}
catch (Exception ex)
{
System.Console.WriteLine(ex);
}
}
Thank you.
Long

A fix is roling out!
This is a problem caused by the Microsoft Exchange WebServices (EWS) of Office365.
As per Microsoft they have found the failure on their Serverside.
Take a look at the comment from Davster (a MS developer) at GitHub (GitHub - EWS MangedAPI issue 204)

Related

Google Drive API to identify the changes in files

I have a list of files and folder stored on a google drive folder. My objective is to identify any changes (modify/create/delete) related to any file/folder within a particular google drive folder i.e get the list of these file name and their drive path.
I have not registered any domain as our spring boot application is deployed on K8's pod and I do not want any notification on any domain or any webhook address. I only want the list of files being modified/deleted when I call the below method/api
Below is the code snippet for spring boot application.
#Component
public class DriveServiceProvider {
#Autowired
private DriveConfig dc;
public Drive getDriveService() throws IOException, GeneralSecurityException {
final GoogleCredentials credentials = GoogleCredentials
.fromStream(new ByteArrayInputStream(new JSONObject(dc.getCred()).toString().getBytes()))
.createScoped(Collections.singletonList("https://www.googleapis.com/auth/drive"));
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
return new Drive.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), requestInitializer)
.setApplicationName(ApplicationConstants.APPLICATION_NAME).build();
}
}
Controller:
#RestController
#RequestMapping("/admin/watch")
public class TestGoogleWatchController {
#Autowired
private DriveServiceProvider driveServiceProvider;
#PostMapping(value = "/googleWatchNotification")
#ResponseStatus(HttpStatus.OK)
public Channel getNotification() throws IOException, GeneralSecurityException {
try {
StartPageToken pageToken = driveServiceProvider.getDriveService().changes().getStartPageToken().execute();
String savedStartPageToken = pageToken.getStartPageToken();
System.err.println(" savedStartPageToken "+savedStartPageToken );
while (savedStartPageToken != null) {
ChangeList changes = driveServiceProvider.getDriveService().changes().list(savedStartPageToken).execute();
System.err.println("======= changes " + changes.toPrettyString());
System.err.println("============ size ::" + changes.getChanges().size());
System.err.println("============ ChangeList ::" + changes.getChanges());
for (Change changeObj : changes.getChanges()) {
System.err.println(" files "+changeObj.getFileId() + " Kind "+changeObj.getKind() + ", Team Drive ID "+changeObj.getTeamDriveId() + ", Type::"+changeObj.getType()+ ",File ::"+changeObj.getFile()+ ", Is Removed::"+changeObj.getRemoved()+ ",Time ::"+changeObj.getTime());
}
}
}catch(Exception ex) {
}
return null;
}
}
*Below is the output after executing:
savedStartPageToken 165
======= changes {
"changes" : [ ],
"kind" : "drive#changeList",
"newStartPageToken" : "165"
}
============ size ::0
============ ChangeList ::[]*
The savedStartPageToken is printing incrementing numeric value after we change anything in drive, however there the ChangeList is always blank.
I am glad that I am answering my own question. The issue was that I was passing the current token in the changeList api.
Actually, the solution is to find the changes since last token till the current token using a loop.

How to download a pdf file from IPFS usng ipfs core api in .net?

Recently i am trying to upload a file to IPFS and download/retrieve it using ipfs core api. And for this purpose a use .net library ipfs(c#) library. its works fine for a txt file but when i uploaded a pdf file and tries to download it gives me some kind of string.i thought that that string maybe my pdf file all content but that string proves me wrong. when i tries to compare my original pdf file string with (current string) that is totally diffferent..
my pdf file hash : QmWPCRv8jBfr9sDjKuB5sxpVzXhMycZzwqxifrZZdQ6K9o
and my c# code the get this(api) ==>
static void Main(string[] args)
{
var ipfs = new IpfsClient();
const string filename = "QmWPCRv8jBfr9sDjKuB5sxpVzXhMycZzwqxifrZZdQ6K9o";
var text = ipfs.FileSystem.ReadAllTextAsync(filename).Result;
}
my question is whtat i have done wrong and i have done some wrong then how can i get a pdf file ?? how ??
First of all please check if you can access to the file from live environment:
e.g.
https://ipfs.infura.io/ipfs/QmNtg1uDy1A71udMa2ipTfKghArRQFspfFkncunamW29SA
https://ipfs.io/ipfs/
if the file was uploaded correctly you can IpfsClient package to do this action:
Define property that references on ipfs env (e.g. via infura)
_ipfsClient = new IpfsClient("https://ipfs.infura.io:5001");
Introduce method to download the file by hash
public async Task<byte[]> DownloadAsync(string hash)
{
using (var stream = await _ipfsClient.FileSystem.ReadFileAsync(hash))
{
using (var ms = new MemoryStream())
{
stream.CopyTo(ms);
return ms.ToArray();
}
}
}
If you use web api - introduce controller to return exactly pdf
public async Task<IActionResult> Get(string hash)
{
var data = await _ipfsDownloadService.DownloadAsync(hash);
return File(data, "application/pdf");
}

Google Drive API - How to make sub-folder into the Team Drive

I'm developing small system using Google Drive API with JAVA,
I am wondering about the TeamDrive API among Google Drive APIs.
First of all, I created team drive folder,
Create Team Drive
public static void createTeamDrive(String accessToken) throws IOException {
long startTime = System.currentTimeMillis();
TeamDrive teamDriveMetadata = new TeamDrive();
teamDriveMetadata.setName("Team Drive API Test");
String requestId = UUID.randomUUID().toString();
TeamDrive teamDrive = getDriveService(accessToken).teamdrives().insert(requestId, teamDriveMetadata).execute();
System.out.println("[Create TeamDrive] execution time : " + (System.currentTimeMillis() - startTime));
}
and then I shared the user.
Share User
public static Permission ShareUser(String teamDriveFolderId, String googleMail, String accessToken) {
long startTime = System.currentTimeMillis();
Permission userPermission = new Permission().setRole("reader")
.setType("user").setEmailAddress(googleMail)
.setValue(googleMail).setWithLink(false);
try {
userPermission = getDriveService(accessToken).permissions().insert(teamDriveFolderId, userPermission)
.setSupportsTeamDrives(true).execute();
System.out.println(userPermission.toPrettyString());
} catch (IOException e) {
System.out.println(e);
}
System.out.println("[Give Permission] execution time : " + (System.currentTimeMillis() - startTime));
return userPermission;
}
And then I tried to create subfolder using google-drive library several times,
But I failed to create sub-folder continuously.
Create Sub-folder
public static void createSubFolder(String accessToken, String teamDriveFolderId) throws IOException {
long startTime = System.currentTimeMillis();
File fileMetaData = new File();
fileMetaData.setTitle("SubFolder Title ");
fileMetaData.setMimeType("application/vnd.google-apps.folder");
fileMetaData.setTeamDriveId(teamDriveFolderId);
fileMetaData.setParents(Arrays.asList(new ParentReference().setId(teamDriveFolderId)));
fileMetaData.set("supportsTeamDrives", true);
fileMetaData.set("fields", "id");
File file = null;
try {
file = getDriveService(accessToken).files().insert(fileMetaData).execute();
System.out.println(file.getId());
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("[Create Sub folder] execution time : " + (System.currentTimeMillis() - startTime));
}
When I call the 'createSubfolderFunction'
I can get 404 response like this.
com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
"code" : 404,
"errors" : [ {
"domain" : "global",
"location" : "file",
"locationType" : "other",
"message" : "File not found: 0AHGrQOmlzQZUUk9PVA",
"reason" : "notFound"
} ],
"message" : "File not found: 0AHGrQOmlzQZUUk9PVA"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
'0AHGrQOmlzQZUUk9PVA' is the exact result from createTeamDrive function.
I referred to this question.enter link description here
Please look at my source-code and point out what went wrong.
I found problem myself,
I should add setSupportTeamDrive(true) when I use the insert method.
file = getDriveService(accessToken).files().insert(fileMetaData).setSupportsTeamDrives(true).execute();
I thing issue with the your folder Id check its your parent folder id of google drive is correct or not
$folderId = '0AIuzzEYPQu9CUk9PVA';
Id is present in the google drive folder URL, after you open the parent folder

How to get Google Drive file ID

I've created a file to Drive root using Google Drive Android API. How can I get this file ID to share it using Google Client Library?
Getting DriveFileResult in ResultCallback<DriveFileResult> callback returns Null:
String fileId = result.getDriveFile().getDriveId().getResourceId();
The callback is to the file being created locally. The DriveId will only have a resourceId when the file is synced to the server. Until then getResourceId will return null.
https://developer.android.com/reference/com/google/android/gms/drive/DriveId.html#getResourceId()
Use CompletionEvents to be notified when syncing with the server has occurred. Then calling getResourceId() should deliver what you are expecting.
this code might help to identify the id for a file present in the google drive.
public static void main(String[] args) throws IOException {
// Build a new authorized API client service.
Drive service = getDriveService();
// Print the names and IDs for up to 10 files.
FileList result = service.files().list()
.setMaxResults(10)
.execute();
List<File> files = result.getItems();
if (files == null || files.size() == 0) {
System.out.println("No files found.");
} else {
System.out.println("Files:");
for (File file : files) {
System.out.printf("%s (%s)\n", file.getTitle(), file.getId());
}
}
}

Setting Description in Metadata for Google Drive Android API

Is there any way to set the Metadata Description?
https://developer.android.com/reference/com/google/android/gms/drive/Metadata.html#getDescription()
If so, what is the length limit?
I can't see anything in the api: https://developer.android.com/reference/com/google/android/gms/drive/MetadataChangeSet.Builder.html
Unfortunately not at the moment, AFAIK. What I do right now is initializing both GDAA and RESTful API (see the 'trash solution' SO 22295903) like this:
private GoogleApiClient _gac;
private com.google.api.services.drive.Drive _svc;
public GoogleApiClient init(String email){
_gac = new GoogleApiClient.Builder(UT.ACTX).addApi(com.google.android.gms.drive.Drive.API)
.addScope(com.google.android.gms.drive.Drive.SCOPE_FILE).setAccountName(email).build();
com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential crd =
GoogleAccountCredential.usingOAuth2(UT.ACTX,
Arrays.asList(com.google.api.services.drive.DriveScopes.DRIVE_FILE));
crd.setSelectedAccountName(email);
_svc = new com.google.api.services.drive.Drive.Builder(
AndroidHttp.newCompatibleTransport(), new GsonFactory(), crd).build();
return this;
}
You get the description from DGAA (GoogleApiClient _gac above), but update/write it to RESTFul like this (off UI thread):
public void oldDescUpW(String titl, String mime, String desc) {
try {
final FileList gLst = _svc.files().list()
.setQ("title = '"+titl+".jpg' and mimeType = '"+mime+"' and trashed = false")
.setFields("items(id)").execute();
if (gLst.getItems().size() == 1) {
final String sId = gLst.getItems().get(0).getId();
com.google.api.services.drive.model.File body =
new com.google.api.services.drive.model.File();
body.setDescription(desc);
_svc.files().patch(sId, body).execute();
}
} catch (Exception e) {}
}
It is also possible to use 'resource ID' from GDAA to address the file in RESTful, but it is not always immediately available (if the file is created in GDAA). See SO 22874657
DISCLAIMER:
It is a HACK and should not stay alive past GDAA delivery of an alternative.