cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

longpoll api returns always true when I added shared folder to my drive

longpoll api returns always true when I added shared folder to my drive

오부경
Explorer | Level 3

When I added shared folder to my drive, longpoll api immediately returns true (no wait).

list_folder api for root folder returns new cursor and longpoll api by root cursor returns true.

When it returns true, I call list_folder api and save cursor.

and after few seconds, I will check changes using longpoll api and api returns true immediately, and I call list_folder again, again.

I thinks it will be make error called 'too_many_requests'.

So, I removed shared folder from drive, it works fine. (wait 30~90seconds and returns false).

 

6 Replies 6

Re: longpoll api returns always true when I added shared folder to my drive

Greg-DB
Dropboxer

When calling list_folder, you need to check the has_more value in the response. If it's true, you need to call back to list_folder/continue with the last returned cursor to get more results. You can find more information on how this works in the documentation for list_folder:

 

https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder

 

If you use a cursor that indicates has_more=true as you are doing, list_folder/longpoll will also immediately indicate that there are more entries to retrieve.

 

Once has_more is false, you can then save the cursor and use list_folder/longpoll to monitor for new changes.

Re: longpoll api returns always true when I added shared folder to my drive

오부경
Explorer | Level 3

Thank you Greg.

I did already list_folder/continue and save cursor

I have no many files in root folder and sub folder. (each folder has 3-10 files)

my code works fine without shared folder.

longpoll returns true just when I add one shared folder.

Added shared folder has 3-4 files.

 

I did test longpoll about root folder, then returns true

I did test longpoll about all children folder in the root, then each longpoll returns false.

Only root folder longpoll returns true.

 

Ps : For test, I call api 'get_latest_cursor' for root folder(empty path), api returns always new cursor.

 

 

Sorry my poor English.

Thanks.

 

 

Re: longpoll api returns always true when I added shared folder to my drive

Greg-DB
Dropboxer
Even if you don't have many files in your account, it's possible the list_folder and list_folder/continue results will be paginated, so you should make sure your app is always checking has_more and calling back if it's true.

If the API isn't working as expected though, please share the API calls an unexpected output so we can look into it. Be sure to redact the access token, but please include the cursors. You can share privately here if you'd prefer:

https://www.dropbox.com/developers/contact

Re: longpoll api returns always true when I added shared folder to my drive

오부경
Explorer | Level 3

I build test code and only run Test function.

Thanks you.

 

 

// for TEST
public class MyDropBoxFile
{
 public string Filename;
 public string Cursor;
 public MyDropBoxFile(string path)
 {
  Filename = path;
 }
}
//
internal List<object> GetFolderList(MyDropBoxFile PathFile)
{
 List<object> dataList = new List<object>();
 string path = PathFile.Filename;
 if (path == "/")
  path = String.Empty;
 Task task = Task.Run(async () =>
 {
  try
  {
   ListFolderResult result = await Client.Files.ListFolderAsync(path).ConfigureAwait(false);
   while (result != null)
   {
    if (String.IsNullOrEmpty(result.Cursor) == false)
    {
     Program.LOGDEBUG("ListFolderAsync result cursor : " + result.Cursor);
     PathFile.Cursor = result.Cursor; // Keep cursor
    }
    else
    {
     Program.LOGDEBUG("ListFolderAsync result cursor is empty");
    }
    foreach (Metadata file in result.Entries)
    {
     dataList.Add(file);
    }
    if (result.HasMore)
    {
     Program.LOGDEBUG("ListFolderAsync result HasMore is true");
     result = await Client.Files.ListFolderContinueAsync(new ListFolderContinueArg(result.Cursor));
    }
    else
    {
     Program.LOGDEBUG("ListFolderAsync result HasMore is false");
     break;
    }
   }
  }
  catch (Exception ex)
  {
   Program.LOGERROR("ListFolderAsync Fail : Exception : " + ex.Message);
  }
 });
 task.Wait();
 return dataList;
}
internal bool IsChanged(MyDropBoxFile PathFile)
{
 bool Changed = false;
 Task task = Task.Run(async () =>
 {
  try
  {
   var longpoll = await Client.Files.ListFolderLongpollAsync(PathFile.Cursor);
   Changed = longpoll.Changes;
  }
  catch (Exception ex)
  {
   Program.LOGERROR("ListFolderLongpollAsync Fail : " + ex.Message);
  }
 });
 task.Wait();
 return Changed;
}
void Test()
{
 MyDropBoxFile file = new MyDropBoxFile("/");
 GetFolderList(file);
 Program.LOGDEBUG("GetFolderList CURSOR : " + file.Cursor);
 for (int i = 0; i < 10; i++)
 {
  if (IsChanged(file))
  {
   Program.LOGDEBUG("IsChanged returns true");
   GetFolderList(file);
   Program.LOGDEBUG("GetFolderList CURSOR : " + file.Cursor);
  }
  else
  {
   Program.LOGDEBUG("IsChanged returns false");
  }
  Thread.Sleep(3000);
 }
}
//==================

 

TESTCASE 1: If i added a shared folder(read/write access) to my drive. OUTPUT:

2017-06-27 13:23:30,920 [DEBUG] ListFolderAsync result cursor : AAGc5OGsaskkYUu4aRmfOmV3SkjpOcNfdg9w6bHlb65ScaDhZaOo6Hd7OGcDX-nVY0C7mbPWZvE2PmIax7exm43-fIxMLaE_F0kngVyQO_kil59gGApZwfO-BB9gWrlqnjkcnw-qsqUbKq_mry6FzUo9-3f12V3cq7VlQCdXa93pm1K-xa974lFrElc9YeQLQKmFd57JkWSo0qOCVmko2L72
2017-06-27 13:23:30,920 [DEBUG] ListFolderAsync result HasMore is false
2017-06-27 13:23:30,920 [DEBUG] GetFolderList CURSOR : AAGc5OGsaskkYUu4aRmfOmV3SkjpOcNfdg9w6bHlb65ScaDhZaOo6Hd7OGcDX-nVY0C7mbPWZvE2PmIax7exm43-fIxMLaE_F0kngVyQO_kil59gGApZwfO-BB9gWrlqnjkcnw-qsqUbKq_mry6FzUo9-3f12V3cq7VlQCdXa93pm1K-xa974lFrElc9YeQLQKmFd57JkWSo0qOCVmko2L72
2017-06-27 13:23:31,783 [DEBUG] IsChanged returns true
2017-06-27 13:23:32,183 [DEBUG] ListFolderAsync result cursor : AAHu00Dl5aNvLxjYe12hvAU89ZjnRZD4N0yKY1TPPOautM6Bfk1Z_Ov8Cegh_4k9KlYMz6mlVQkcU-rpf4K-31tsCXyWv-J2OEYFUvD1P6mfzfArURF_BoBdD3NbC_cd0qS74VnnNdGxiO9Qe9JWKvqCmdo4lfiAdrmyaH9rCWQOaDJ0uVlK5DZYBtcxKa4EKfW4CfSjiYhmcWuSNkpoox-d
2017-06-27 13:23:32,183 [DEBUG] ListFolderAsync result HasMore is false
2017-06-27 13:23:32,199 [DEBUG] GetFolderList CURSOR : AAHu00Dl5aNvLxjYe12hvAU89ZjnRZD4N0yKY1TPPOautM6Bfk1Z_Ov8Cegh_4k9KlYMz6mlVQkcU-rpf4K-31tsCXyWv-J2OEYFUvD1P6mfzfArURF_BoBdD3NbC_cd0qS74VnnNdGxiO9Qe9JWKvqCmdo4lfiAdrmyaH9rCWQOaDJ0uVlK5DZYBtcxKa4EKfW4CfSjiYhmcWuSNkpoox-d
2017-06-27 13:23:35,556 [DEBUG] IsChanged returns true
2017-06-27 13:23:35,909 [DEBUG] ListFolderAsync result cursor : AAHNmC3IA4hHEYmji8hV0PSkp58gcJHHsq1rRuE1LuUFk7hudcMOYCajiqHhHzt-Zygdj27kUgxfRW4sViv-d_yPFcbSVTQT7BeoOBEaEnU6yRc6kMquR0svOhmMq3A4OW_HEnEwwKm1vWfBB79SEMR3Z_NVbUNUnzbhgQRGzi8RuQe59vuQF1cCyW9ebLwfLTCDSG_7lvy0TnUK1VtI5fwH
2017-06-27 13:23:35,909 [DEBUG] ListFolderAsync result HasMore is false
2017-06-27 13:23:35,925 [DEBUG] GetFolderList CURSOR : AAHNmC3IA4hHEYmji8hV0PSkp58gcJHHsq1rRuE1LuUFk7hudcMOYCajiqHhHzt-Zygdj27kUgxfRW4sViv-d_yPFcbSVTQT7BeoOBEaEnU6yRc6kMquR0svOhmMq3A4OW_HEnEwwKm1vWfBB79SEMR3Z_NVbUNUnzbhgQRGzi8RuQe59vuQF1cCyW9ebLwfLTCDSG_7lvy0TnUK1VtI5fwH
2017-06-27 13:23:39,291 [DEBUG] IsChanged returns true
2017-06-27 13:23:39,691 [DEBUG] ListFolderAsync result cursor : AAHSnSi_2OBrCp9A2sKf4spo-_2wg01q3ldglng6S1UaOlsrw-slvhKL5NCZtOskjG4HZ9ZC5VIaEzISTWy3su-Qgy57OUMHGRBCmtgVFZfieQfknrYJNPSKliJwCsxPjzQZaggIu_F9wK9yqadkiMptttOTqwn4Bm18b50WgxfRqIKi_PucHSmHp8yA2QTaoT_DTOCw_S48Qdq_6oci92e-
2017-06-27 13:23:39,691 [DEBUG] ListFolderAsync result HasMore is false
2017-06-27 13:23:39,691 [DEBUG] GetFolderList CURSOR : AAHSnSi_2OBrCp9A2sKf4spo-_2wg01q3ldglng6S1UaOlsrw-slvhKL5NCZtOskjG4HZ9ZC5VIaEzISTWy3su-Qgy57OUMHGRBCmtgVFZfieQfknrYJNPSKliJwCsxPjzQZaggIu_F9wK9yqadkiMptttOTqwn4Bm18b50WgxfRqIKi_PucHSmHp8yA2QTaoT_DTOCw_S48Qdq_6oci92e-
2017-06-27 13:23:43,063 [DEBUG] IsChanged returns true
2017-06-27 13:23:43,447 [DEBUG] ListFolderAsync result cursor : AAGWl4_PXFJ7EgSQU7fSg1FMc08xQtvFzuFADLMVuwqOpCNVZw8HEgjkKIsZUapF4J52tD9VtHEZ1Vlb4R3UdhB9zR_9bf-uvRhlwjkod8XImUsoMc1VzKy-FBIvbPh5bqXp_QrwOjLXpqEASVDa5_0pAOVUdqJQSXFZEPHnd8vhpVmhIenvrQLj47a-A7-ilvmfG_gGmA--QyuO1leasLnn
2017-06-27 13:23:43,447 [DEBUG] ListFolderAsync result HasMore is false
2017-06-27 13:23:43,447 [DEBUG] GetFolderList CURSOR : AAGWl4_PXFJ7EgSQU7fSg1FMc08xQtvFzuFADLMVuwqOpCNVZw8HEgjkKIsZUapF4J52tD9VtHEZ1Vlb4R3UdhB9zR_9bf-uvRhlwjkod8XImUsoMc1VzKy-FBIvbPh5bqXp_QrwOjLXpqEASVDa5_0pAOVUdqJQSXFZEPHnd8vhpVmhIenvrQLj47a-A7-ilvmfG_gGmA--QyuO1leasLnn
2017-06-27 13:23:46,819 [DEBUG] IsChanged returns true
2017-06-27 13:23:47,235 [DEBUG] ListFolderAsync result cursor : AAFmQ-D-iKpaRuup7hlIxrYeYKkUNXxkyHPFdpeKBDecLzh0QeDeHeMbkXtsZQVtLbiEmsqgc4sh9oq0tMHockcVCHHQYTXq01__cBpeHBFLlLfVyeXqpmdBKafNoTQdWKEALkbTNssgP1aZvWFRGYP2dlU1RI8GqOu_VuMX0d3O3L-i7ZCTOS2Td6XYbaMBbURqf3m4NdWhQU5G89hwyfA9
2017-06-27 13:23:47,235 [DEBUG] ListFolderAsync result HasMore is false
2017-06-27 13:23:47,235 [DEBUG] GetFolderList CURSOR : AAFmQ-D-iKpaRuup7hlIxrYeYKkUNXxkyHPFdpeKBDecLzh0QeDeHeMbkXtsZQVtLbiEmsqgc4sh9oq0tMHockcVCHHQYTXq01__cBpeHBFLlLfVyeXqpmdBKafNoTQdWKEALkbTNssgP1aZvWFRGYP2dlU1RI8GqOu_VuMX0d3O3L-i7ZCTOS2Td6XYbaMBbURqf3m4NdWhQU5G89hwyfA9
2017-06-27 13:23:50,615 [DEBUG] IsChanged returns true
2017-06-27 13:23:51,021 [DEBUG] ListFolderAsync result cursor : AAFnYct-TkyTGcD8pDozc9wiKBQL2kNDgFrMJYLg1GY33UMsFoD976SYY4pe8xP6aa0Bus5TWN8yMsPQeNx1N0SrDGIkme_LQtk2mnmfrCtHspJrrCp0qHt8TM4eG7HrVPpWWag2XVIkPX7e8E0GjcFv4uBHwoyiG5kcXsNwivO5l2d_hD-ZUAexTNqOM60dKbg0AjmjYqDHOFzLew3wG_3g
2017-06-27 13:23:51,021 [DEBUG] ListFolderAsync result HasMore is false
2017-06-27 13:23:51,037 [DEBUG] GetFolderList CURSOR : AAFnYct-TkyTGcD8pDozc9wiKBQL2kNDgFrMJYLg1GY33UMsFoD976SYY4pe8xP6aa0Bus5TWN8yMsPQeNx1N0SrDGIkme_LQtk2mnmfrCtHspJrrCp0qHt8TM4eG7HrVPpWWag2XVIkPX7e8E0GjcFv4uBHwoyiG5kcXsNwivO5l2d_hD-ZUAexTNqOM60dKbg0AjmjYqDHOFzLew3wG_3g
2017-06-27 13:23:54,420 [DEBUG] IsChanged returns true
2017-06-27 13:23:54,771 [DEBUG] ListFolderAsync result cursor : AAFSGLFZByg4yBITx8a158MhwUWtLeum2HHEkQpScrK4rZ-UioWqHS475zeh9rrt7I5L9xhc-9ZGZGalYlMOGgTff80z7JeWkCJpnMMmuMHpw5jrsCu0sUZY6Yj7oOUuDAdr-Hwhgh8hEM3z54KIba72T_IVpemprW4qgVJsvWb9gAk_ph-11Ji6T2qPSlGtLzOODhYeLFrKUSZpsBM24VCl
2017-06-27 13:23:54,786 [DEBUG] ListFolderAsync result HasMore is false
2017-06-27 13:23:54,786 [DEBUG] GetFolderList CURSOR : AAFSGLFZByg4yBITx8a158MhwUWtLeum2HHEkQpScrK4rZ-UioWqHS475zeh9rrt7I5L9xhc-9ZGZGalYlMOGgTff80z7JeWkCJpnMMmuMHpw5jrsCu0sUZY6Yj7oOUuDAdr-Hwhgh8hEM3z54KIba72T_IVpemprW4qgVJsvWb9gAk_ph-11Ji6T2qPSlGtLzOODhYeLFrKUSZpsBM24VCl
2017-06-27 13:23:58,158 [DEBUG] IsChanged returns true
2017-06-27 13:23:58,527 [DEBUG] ListFolderAsync result cursor : AAEgJPkNvGsgId0qiFBhKpK9-ikvAlriI5JP_-eImvMdMquyfpWJZUPtz-YsZTj_CKmgOAgfg3m2YlPDzDnQu6o8sLg67z2-ggm60f0d6CaM4PDOLkp6sDeypTad1Fw-8VHR2AXMIgqwVtycPosTCi6hjQJg34wyg775-jNXU7WgRfBHBHGAFFjJGc6FlWy4eiJZTrj6WonGakEE0eocU8Yu
2017-06-27 13:23:58,527 [DEBUG] ListFolderAsync result HasMore is false
2017-06-27 13:23:58,527 [DEBUG] GetFolderList CURSOR : AAEgJPkNvGsgId0qiFBhKpK9-ikvAlriI5JP_-eImvMdMquyfpWJZUPtz-YsZTj_CKmgOAgfg3m2YlPDzDnQu6o8sLg67z2-ggm60f0d6CaM4PDOLkp6sDeypTad1Fw-8VHR2AXMIgqwVtycPosTCi6hjQJg34wyg775-jNXU7WgRfBHBHGAFFjJGc6FlWy4eiJZTrj6WonGakEE0eocU8Yu
2017-06-27 13:24:01,892 [DEBUG] IsChanged returns true
2017-06-27 13:24:02,262 [DEBUG] ListFolderAsync result cursor : AAGaM9u4S5fYS4Lk0MBDsWxaRRcQytzhRD-XF9IgF5ZrjMnFH3gXjHkWNQn8MI_jFK8pgWoWR97Er0OUk8pqGuzO2f4M9S_a0PCBasqEBZ4P6F0Msw3s9tAxBhW6SW-kzReWR9Pz-WXRioaC2IxaLx3RJsUNNRbaS-XM8jJQbM0h7zccV1eF60KxM0ParoM9A_5fQrIbkzheGkGbXXsQIuHG
2017-06-27 13:24:02,262 [DEBUG] ListFolderAsync result HasMore is false
2017-06-27 13:24:02,262 [DEBUG] GetFolderList CURSOR : AAGaM9u4S5fYS4Lk0MBDsWxaRRcQytzhRD-XF9IgF5ZrjMnFH3gXjHkWNQn8MI_jFK8pgWoWR97Er0OUk8pqGuzO2f4M9S_a0PCBasqEBZ4P6F0Msw3s9tAxBhW6SW-kzReWR9Pz-WXRioaC2IxaLx3RJsUNNRbaS-XM8jJQbM0h7zccV1eF60KxM0ParoM9A_5fQrIbkzheGkGbXXsQIuHG
2017-06-27 13:24:05,635 [DEBUG] IsChanged returns true
2017-06-27 13:24:06,013 [DEBUG] ListFolderAsync result cursor : AAHGWo0QMte94lLPvPGVN8BEuBQzkBUXSR546pLdlDDN7RWI-TG76CNFqqLXOWmhbNWAbEsZrJhwreaxssZCAKQxnlAsABXyxf-7MEZARbkL4cdpSSoAfbS9izRIrrvOOsRwacbje-xqrooC4UkuTBfpQkCZDGeccULXJKSUobU54ma0EVZYIN9WsEuwwnmWRB_0zTJU5BtwFBrbRxAr4A-c
2017-06-27 13:24:06,013 [DEBUG] ListFolderAsync result HasMore is false
2017-06-27 13:24:06,013 [DEBUG] GetFolderList CURSOR : AAHGWo0QMte94lLPvPGVN8BEuBQzkBUXSR546pLdlDDN7RWI-TG76CNFqqLXOWmhbNWAbEsZrJhwreaxssZCAKQxnlAsABXyxf-7MEZARbkL4cdpSSoAfbS9izRIrrvOOsRwacbje-xqrooC4UkuTBfpQkCZDGeccULXJKSUobU54ma0EVZYIN9WsEuwwnmWRB_0zTJU5BtwFBrbRxAr4A-c

TESTCASE 2 : Just remove a shared folder from my drive and test again. OUTOUT:
2017-06-27 13:27:14,896 [DEBUG] ListFolderAsync result cursor : AAHA6xuh9msxmApG3USBbTi6tOyaowlz-ZbSuoH3HjFyQ_eymn-YII03nNmuAD0ltM7w9mS1wYA61Koum27agcjqFQ_Xszf-00QBKUU0QbGuUe_ifpOl8MBBRCbEHtIZFS_bg9f-CeYXNrFBvAFGCEd2OMr8WGd4z1M2tK3SlmBqgw
2017-06-27 13:27:14,896 [DEBUG] ListFolderAsync result HasMore is false
2017-06-27 13:27:14,911 [DEBUG] GetFolderList CURSOR : AAHA6xuh9msxmApG3USBbTi6tOyaowlz-ZbSuoH3HjFyQ_eymn-YII03nNmuAD0ltM7w9mS1wYA61Koum27agcjqFQ_Xszf-00QBKUU0QbGuUe_ifpOl8MBBRCbEHtIZFS_bg9f-CeYXNrFBvAFGCEd2OMr8WGd4z1M2tK3SlmBqgw
2017-06-27 13:27:46,387 [DEBUG] IsChanged returns false
2017-06-27 13:28:21,830 [DEBUG] IsChanged returns false
2017-06-27 13:29:08,350 [DEBUG] IsChanged returns false
2017-06-27 13:29:57,361 [DEBUG] IsChanged returns false
2017-06-27 13:30:31,179 [DEBUG] IsChanged returns false
2017-06-27 13:31:14,460 [DEBUG] IsChanged returns false
2017-06-27 13:32:01,208 [DEBUG] IsChanged returns false
2017-06-27 13:32:53,843 [DEBUG] IsChanged returns false
2017-06-27 13:33:34,006 [DEBUG] IsChanged returns false
2017-06-27 13:34:30,179 [DEBUG] IsChanged returns false

Re: longpoll api returns always true when I added shared folder to my drive

Greg-DB
Dropboxer
Thanks! That's helpful. We're looking into it.

Re: longpoll api returns always true when I added shared folder to my drive

오부경
Explorer | Level 3

I'm sorry for the short English. I used Google Translator

I have read dropbox documents very deeply again on this issue.

If I use get_lastest_cursor and longpoll to get changes only, I'm using it wrong.

I realized I could get a Delta using the "list_folder/continue" call.

So, I came to understand the relationship between Cursor and Delta in turn.

I've found that it works well only with a good understanding of the behavior of get_lastest_cursor, longpoll, and list_folder/continue.

After modifying the code, it works fine now.

For someone like me, leave the reference code below.

 

Thanks Greg K.

void CheckChanges()
{
	string LastCursor = String.Empty;

	// first step : get new cursor and keep
	Task task = Task.Run(async () =>
	{
		ListFolderArg arg = new ListFolderArg("", true, false, true, false);
		var result = await Client.Files.ListFolderGetLatestCursorAsync(arg);
		LastCursor = result.Cursor;
	});
	task.Wait();

	// loop : detect changes and get delta
	while(!EndOfCheck)
	{
		bool doGetDelta = false;
		Task task = Task.Run(async () =>
		{
			try
			{
				var longpoll = await Client.Files.ListFolderLongpollAsync(PathFile.Cursor);

				doGetDelta = longpoll.Changes;
			}
			catch
			{
			}
		});
		task.Wait();

		if(doGetDelta)
		{
			List<MyChangeInfo> changeList = new List<MyChangeInfo>();
			ListFolderContinueArg arg = new ListFolderContinueArg(LastChangeCursor);
			Task task = Task.Run(async () =>
			{
				try
				{
					var continueResult = await Client.Files.ListFolderContinueAsync(arg);
					LastChangeCursor = continueResult.Cursor; // keep cursor
					if (continueResult.Entries != null && continueResult.Entries.Count > 0)
					{
						foreach (var entry in continueResult.Entries)
						{
							MyChangeInfo change = new MyChangeInfo();
							change.key = entry.PathLower;
							change.metadata = entry;
							change.removed = entry.IsDeleted;
							changeList.Add(change);
						}
					}
				}
				catch
				{
				}
			});
			task.Wait();

			if(newList.Count > 0)
			{
				// Do Apply Changes
				foreach(var change in newList)
				{
					if(change.removed)
					{
					// do delete file or folder
					}
					else
					{
					// do update or add
					}
				}
			}
		}
	}
}

 



Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    오부경 Explorer | Level 3
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?