Comments (4)
Yes we could use this. :)
Thanks,
Jim
On Jan 20, 2012, at 12:06 PM, "Prabir Shrestha" [email protected] wrote:
https://developers.facebook.com/blog/post/627/
We would most probably want a method that looks similar to this.
dynamic result = fb.Api("GET", "me", new { fields = new { "id", "name"}, etag = "...." });
dynamic headers = result.headers;
dynamic etag = result.headers.etag;
dynamic body = result.body;Then result.body actually contains the actual json result.
etag parameter is a special parameter like the "access_token" parameter. it should be set as a request header instead of normal parameter.
Reply to this email directly or view it on GitHub:
#35
from facebook-csharp-sdk.
added etag support for sync methods. Does not yet work for batch requests and async methods.
The ETag is calculated using the entire response from the API call including its formatting. Developers should be aware that the formatting of API response output may be impacted by the user agent string. Therefore, calls originating from the same client should keep the user agent consistent between calls. (https://developers.facebook.com/blog/post/627/)
FacebookClient.SetDefaultHttpWebRequestFactory(
uri =>
new HttpWebRequestWrapper((HttpWebRequest)WebRequest.Create(uri)) { UserAgent = "Facebook C# SDK" });
Normal request still works like v5.
var fb = new FacebookClient("access_token");
dynamic result = fb.Get("me", new { fields = "id,name"});
string id = result.id;
For etag you need to pass the special parameter called etag
For the first request it should be empty string
dynamic result1 = fb.Get("me", new { fields = "id,name", _etag_ = string.Empty});
This will tell the fb c# sdk to return a JsonObject with headers and body.
dynamic headers = result1.headers; // JsonObject of headers.
dynamic body = result1.body; // The actual json response.
// to access the actual json response use result.body.x instead of just result.x
string id = result1.body.id;
then the you can use the etag from the previous response to get the next responses.
dynamic result2 = fb.Get("me", new {fields = "id,name", _etag_ = result1.headers.ETag});
dynamic headers = result1.headers;
// always check if the response has a body.
if(result2.ContainsKey("body")) {
// we've got the updated response.
string id = result1.id;
}
else {
// the last request was the latest.
// so do nothing.
}
Note: result1.header.ETag (make sure ETag contains the right capitalization). It is exactly how Facebook returns the response header.
when etag is string.Empty it will always return a body, so you don't need to check result1.ContainsKey("body") for it.
from facebook-csharp-sdk.
Sample code for using etag with async methods.
Note: If you are using XAsync methods make sure to use different instance of FacebookClient. Use same instance only if you are using with XTaskAsync.
var firstFb = new FacebookClient(accessToken);
var secondFb = new FacebookClient(accessToken);
secondFb.GetCompleted +=
(o, e) =>
{
if (e.Cancelled)
{
Console.WriteLine("cancelled");
return;
}
else if (e.Error != null)
{
Console.WriteLine(e.Error.Message);
return;
}
dynamic result = e.GetResultData();
Console.WriteLine(result.ToString());
Console.WriteLine(result.ContainsKey("body"));
};
firstFb.GetCompleted +=
(o, e) =>
{
if (e.Cancelled)
{
Console.WriteLine("cancelled");
return;
}
else if (e.Error != null)
{
Console.WriteLine(e.Error.Message);
return;
}
dynamic result = e.GetResultData();
Console.WriteLine(result.ToString());
Console.WriteLine(result.ContainsKey("body"));
secondFb.GetAsync("me?fields=id,name", new { _etag_ = result.headers.ETag });
};
firstFb.GetAsync("me?fields=id,name", new { _etag_ = string.Empty });
from facebook-csharp-sdk.
Here is an example of using etags in batch requests.
var fb = new FacebookClient(accessToken);
dynamic result = fb.Batch(
new FacebookBatchParameter("me", new { _etag_ = string.Empty }),
new FacebookBatchParameter("me", new { _etag_ = "\"ac9e51b60e883e294cc98f35f70a1ec8fdf0e736\"" }),
new FacebookBatchParameter("me") { Data = new { headers = new Dictionary<string, object> { { "If-None-Match", "\"ac9e51b60e883e294cc98f35f70a1ec8fdf0e736\"" } } } });
from facebook-csharp-sdk.
Related Issues (20)
- Update links to docs accordingly
- Error On Video Upload To Page
- Which graph version APIs we are using for facebook UWP nuget package? HOT 3
- SDK support? HOT 3
- Assembly version number is not getting updated with versions
- Facebook is deprecating publish_actions persmission, can we still use this SDK?
- unkown facebook response
- System.Exception: Unknown Error Occured --> System.UriFormatException: Invalid URI: The Uri string is too long HOT 2
- Get Page Post Picture
- Could not install package 'Facebook 7.0.6' HOT 1
- Video caption - language spec. character became "?"
- Depracted facebook web sdk..?
- Add support for Graph API v3.2?
- Image posts with text message do not post the message HOT 2
- Your homepage has links to Casinos?
- A general query
- Is this project dead? HOT 1
- Where can I find connected pages?
- Moving to the new .NET Foundation CLA service HOT 1
- .Net Core 8.0 Feature Request
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facebook-csharp-sdk.