I'm making an async batch request with 50 report post request on it.
The first batch request returns me the Report Ids
1st Step
dynamic report_ids = await fb.PostTaskAsync(new
{
batch = batch,
access_token = token
});
Next I'm getting the reports info, to get the async status to see if they are ready to be downloaded.
2st Step
var tListBatchInfo = new List<DataTypes.Request.Batch>();
foreach (var report in report_ids)
{
if (report != null)
tListBatchInfo.Add(new DataTypes.Request.Batch
{
name = !ReferenceEquals(report.report_run_id, null) ? report.report_run_id.ToString() : report.id,
method = "GET",
relative_url = !ReferenceEquals(report.report_run_id, null) ? report.report_run_id.ToString() : report.id,
});
}
dynamic reports_info = await fb.PostTaskAsync(new
//dynamic results = fb.Post(new
{
batch = JsonConvert.SerializeObject(tListBatchInfo),
access_token = token
});
Some of the ids generated in the first step are returning this error, once I call them in the second step
Message: Unsupported get request. Object with ID '6057XXXXXX'
does not exist, cannot be loaded due to missing permissions, or does
not support this operation. Please read the Graph API documentation at
https://developers.facebook.com/docs/graph-api
I know the id is correct because I can see it in using facebook api explorer. What am I doing wrong?
This may be caused by Facebook's replication lag. That typically happens when your POST request is routed to server A, returning report ID, but query to that ID gets routed to server B, which doesn't know about the report existence yet.
If you try to query the ID later and it works, then it's the lag. Official FB advice for this is to simply wait a bit longer before querying the report.
https://developers.facebook.com/bugs/250454108686614/
Related
I am using PowerShell and CSOM to mirror Sharepoint Online and OneDrive sites with all their files.
Consequently, after a few thousand files/a few hours of file download, an "The operation has timed out" exception is thrown, as expected. This is due to Microsoft's throttling.
To prevent the timeout, I am using the RequestTimeOut Paramter of the CSOM context, and also doing incremental retry, and also throttling the amount of ExecuteQuery() calls to 2 per second, and also decorating the CSOM call. That is all not enough, though.
The http response header of the failed call is supposed to include a "Retry-After" line, which I would like to use to time the retry.
The Exception happens either during Microsoft.SharePoint.Client.ClientContext's ExecuteQuery() or [Microsoft.SharePoint.Client.File]::OpenBinaryDirect().
Here is some simplified code extract:
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($WebURL)
$Context.Credentials = $spoCredential
$Context.RequestTimeout = 60000; # 1 min
$Context.add_ExecutingWebRequest({
param($Source, $EventArgs)
$request = $EventArgs.WebRequestExecutor.WebRequest
$request.UserAgent = "XXX|CsomPs|MyScript/1.0"
})
$Web = $Context.Web
$Context.Load($Web)
$Context.ExecuteQuery()
Which all works perfectly well, until the "The operation has timed out" exception is thrown. Say, $Context.ExecuteQuery() of the sample throws the exception.
How do I access the http response and especially the http response headers and even more especially the Retry-After header within my CSOM powershell script?
Thanks!
First thing, you can't access and custom HTTP response. This is handled by SharePoint Online side.
Second, you should avoid getting throttled or blocked in SharePoint Online.
Microsoft don't have exact throttling limit, so it's better for you to reduce the number of operations per request or reduce frequency of calls
Here is the code of decorating traffic in CSOM
// Get access to source site
using (var ctx = new ClientContext("https://contoso.sharepoint.com/sites/team"))
{
//Provide account and pwd for connecting to SharePoint Online
var passWord = new SecureString();
foreach (char c in pwd.ToCharArray()) passWord.AppendChar(c);
ctx.Credentials = new SharePointOnlineCredentials("contoso#contoso.onmicrosoft.com",
passWord);
// Add our User Agent information
ctx.ExecutingWebRequest += delegate (object sender, WebRequestEventArgs e)
{
e.WebRequestExecutor.WebRequest.UserAgent = "NONISV|Contoso|GovernanceCheck/1.0";
};
// Normal CSOM Call with custom User-Agent information
Web site = ctx.Web;
ctx.Load(site);
ctx.ExecuteQuery();
}
If this is not helpful, you can follow up CoreThrottling this demonstration.
You can access the headers from the failed CSOM response this way. This is interchangeable to Powershell.
try {
context.ExecuteQuery();
}
catch(WebException wex) {
var response = wex.Response as HttpWebResponse;
if (response != null && (response.StatusCode == (HttpStatusCode)429 || response.StatusCode == (HttpStatusCode)503))
{
// Reference the headers in the throttled / failed response
response.Headers
}
}
Full MS code sample (search page for .RetryQuery): https://learn.microsoft.com/en-us/sharepoint/dev/general-development/how-to-avoid-getting-throttled-or-blocked-in-sharepoint-online
After some extensive throttling, i have never actually seen the Retry-After value come back as anything other than 120 (seconds).
In my scenario, there is a plugin (Retrieve Multiple) on Annotation. This plugin is nothing just a part of BLOB Storage solution(used for Attachment Management solution provided by Microsoft). So, it is clear that in our CRM, MicrosoftlLabsAzureBlobstorage is being used.
Now, I am executing a console app which retrieves multiple annotations through Query Expression. When it tries to fetch records around 500 or 600, it throws below error.
{The plug-in execution failed because no Sandbox Hosts are currently
available. Please check that you have a Sandbox server configured and
that it is running.\r\nSystem.ServiceModel.CommunicationException:
Microsoft Dynamics CRM has experienced an error. Reference number for
administrators or support: #AFF51A0F"}
When I fetch specific records or very less records, it executes fine.
So, I my question is that is there any limitation in number for Rerieve Multiple Query ? if retrievemultiple PlugIn exists ?
Is there any other clue that I am not able to find ?
To work around this conflict, in your console application code you may want to try retrieving smaller pages of annotations, say 50 at a time, and loop through the pages to process them all.
This article provides sample code for paging a QueryExpression.
Here's the abridged version of that sample:
// The number of records per page to retrieve.
int queryCount = 3;
// Initialize the page number.
int pageNumber = 1;
// Initialize the number of records.
int recordCount = 0;
// Create the query expression
QueryExpression pagequery = new QueryExpression();
pagequery.EntityName = "account";
pagequery.ColumnSet.AddColumns("name", "emailaddress1");
// Assign the pageinfo properties to the query expression.
pagequery.PageInfo = new PagingInfo();
pagequery.PageInfo.Count = queryCount;
pagequery.PageInfo.PageNumber = pageNumber;
// The current paging cookie. When retrieving the first page,
// pagingCookie should be null.
pagequery.PageInfo.PagingCookie = null;
while (true)
{
// Retrieve the page.
EntityCollection results = _serviceProxy.RetrieveMultiple(pagequery);
if (results.Entities != null)
{
// Retrieve all records from the result set.
foreach (Account acct in results.Entities)
{
Console.WriteLine("{0}.\t{1}\t{2}", ++recordCount, acct.Name,
acct.EMailAddress1);
}
}
// Check for more records, if it returns true.
if (results.MoreRecords)
{
// Increment the page number to retrieve the next page.
pagequery.PageInfo.PageNumber++;
// Set the paging cookie to the paging cookie returned from current results.
pagequery.PageInfo.PagingCookie = results.PagingCookie;
}
else
{
// If no more records are in the result nodes, exit the loop.
break;
}
}
This page has more info and another sample.
I'm working on a console application to download statuses and such from my own account -- nothing production or public. I'm finding that I can only get the last 100 statuses, but I was hoping to at least go a couple of years back.
I'm using the C# API, with something like:
dynamic response = Client.Get(string.Format("{0}/statuses", Secrets.FacebookUserName));
while (response.data.Count > 0)
{
foreach (dynamic status in response.data)
{
// do stuff
}
response = Client.Get(response.paging.next);
}
This works fine, but stops after 100 records.
I see the same thing when trying to use FQL:
dynamic x = Client.Get("fql", new { q = "select message from status where uid=me() limit 1000" });
Do I need to go down the road of exploring the batch API?
I use REST API in JavaScript. When I request REST API multiple times, it returns(response) invalid session id, but I am providing a valid session id, because I have pulled data with this session id.
Anyone came across this issue?
function sugarLogin(url, user, password) {
var request = new XMLHttpRequest();
var params = {
user_auth: {
user_name: user,
password: password
},
name_value_list: [{
name: 'notifyonsave',
value: 'true'
}]
};
var json = $.toJSON(params);
var crm_api = url;
request.open("POST", crm_api, true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
var response = request.responseText;
var response_obj = jQuery.parseJSON(response);
if (response_obj) {
if (response_obj.name && response_obj.name == "Invalid Login") {
//invalid login
ProcessingFlag = 3;
} else {
session_id = response_obj.id;
ProcessingFlag = 1;
}
}
} else if (request.readyState == 4 && request.status == 404) {
ProcessingFlag = 2;
}
}
request.send("method=login&input_type=JSON&response_type=JSON&rest_data=" + json);}
I have used above code to login and set session_id (global scope)
and then using this session id I am calling search_by_module function of REST API.
It is working fine but if made multiple requests frequently then it says invalid session id.
Although I have tried to call login function again before making search_by_module call.
Main issue is when I tried calling other REST function after response returned from search_by_module and rendered HTML, it says me invalid session. I can't figure out why session expires immediately while we know that on server session expires after 24 minutes (server where our sugar instance hosted)
I bet you're getting this because of item number 3 :
1/ Defined an error callback that checks for that particular response -invalid login- and calls the login function. Reading your code, I guess this is ProcessingFlag = 3; job.
2/ make sure the login function updates the session_id correctly and globally so that future function calls will get the correct value.
3/ make sure you're passing that new session_id to all your subsequent calls as FIRST parameter in all you rest_data. I got caught on this and lost many hours only to find out that SugarCRM DOESN'T support named parameters in its rest_data (is it poorely implemented function-arguments-wise ?) This is because I was adding session_id as last parameter and all of my REST calls were returning invalid ID.
i need to make a page that will have a request dialog for a facebook page or a facebook app.
I need to get the number of friends the user sent the request to and at the end of the day the number of request that got accpeted from the specific user.
The scenario is for giving awards , the user that sent the most request to freinds gets an award and the user that had the most requests accepted also gets an award.
I dont know if the seccond is possible , but i think it should be , couse games on FB give u points for sent request and also u get new missions when friends accept your request , so there mut be a way.
--
I will record the number of invites sent.
Return Data
request_ids
A comma-separated list of the request_ids that were created. To learn who the requests were sent to, you should loop through the information for each request object identified by a request id.
FB.ui({
method: 'apprequests',
title:'Suggest '+fbAppName+' to your friends',
message: 'I thought you would dig this app!',
data: 'gameID=96'
}, onInviteFriend);
//jquery required for ajax function
onInviteFriend = function(response) {
if (response && response.request_ids) {
var idsLength = response.request_ids.length;
var idList = "";
var data = {};
var ajaxSettings = {};
for (var i = 0; i < idsLength; i++){
idList += response.request_ids[i];
if (i < idsLength-1){
idList += ",";
}
}
if (idsLength > 0){
data.idList = idList;
ajaxSettings = {
type: "GET",
url: sketchnpass.root+"/ajax/log-invite-sent/",
data: data,
success: sketchnpass.onSaveInvites
};
$.ajax(ajaxSettings);
}
//was published
} else {
//was not published
}
}
i think using the code above i can get the number of sent requests.
But when some1 accepts the request how will i know that happened , does the accepted request send the user to my app along with some data?
The Facebook requests dialog documentation basically walks you through how to do this.
When requests are sent, request_ids is returned as return data so you would want to log this information in your system to track who sent how many requests.
To track accepted invitations, the documentation says that this url is called: http://apps.facebook.com/[app_name]/?request_ids=012345678910 so you would just need to parse the request id and look that request id up in your system and mark it as accepted.