I'm using Facebook C# API and I want to create a custom "Like" action, allowing the user to like objects outside of Facebook.
The user will be allowed to "Like" a custom object, like an Apple or a Book, and the app has to post this information in the user timeline.
I've tried
dynamic res = fb.Post("me/og.likes", new
{
message = "My first like post using Facebook SDK for .NET"
});
But this gives me the following FacebookApiException exception
(Exception - #1611072) The action you're trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: object.
But if I try
dynamic res = fb.Post("me/og.likes", new
{
object="http://samples.ogp.me/226075010839791"
});
it doesn't even compile, since object is a reserved word on C#.
What should I do?
Is it possible?
Try escape using #:
dynamic res = fb.Post("me/og.likes", new
{
#object="http://samples.ogp.me/226075010839791"
});
EDIT: For other special characters you should be able to use a dictionary instead of a anonymous typed object:
var postInfo = new Dictionary<string, object>();
postInfo.Add("fb:explicitly_shared", "your data");
dynamic res = fb.Post("me/og.likes", postInfo);
Related
I want to make a simple application C# with docusign.
I created a template on the site with several fields that the user will have to fill in. The application simply chooses the email address of the candidate.
I do like this for create my Envelope :
TemplateRole tRoleSigner = new TemplateRole();
tRoleSigner.Email = DSConfig.Signer1Email;
tRoleSigner.Name = DSConfig.Signer1Name;
tRoleSigner.RoleName = "Candidat";
TemplateRole tRoleCC = new TemplateRole();
tRoleCC.Email = DSConfig.Cc1Email;
tRoleCC.Name = DSConfig.Cc1Name;
tRoleCC.RoleName = "EnCopie";
List<TemplateRole> rolesList = new List<TemplateRole>() { tRoleSigner, tRoleCC };
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition
{
EmailSubject = "Signatures des documents relatifs à une promesse d'embauche",
TemplateRoles = rolesList,
TemplateId = DSConfig.TemplateID,
Status = "sent"
};
I tested but the fields do not appear on the document ...
However if I directly use the template via docusign the fields are there!
I know that we can create a tab in the C # code but I want to use the fields defined on the site!
I think I'm missing something ...
Without more information, including logs and IDs can't be sure what is the issue.
Possibilities:
RoleName is wrong/mismatch. Must be the one in the template that you use the ID for.
Fields are using anchor tags that are not found in document.
Template is in production and you are using developer account.
You can also try the web app ("directly") again and enable to see the API logs. The web app uses the same API that you do, and this way you can see exactly how it's done.
I write function for search in youtube.
I create project on "console.developers.google.com" . the name project is youtubesearch and I get apiKey.
I have the error
"An unhandled exception of type
'Google.GData.Client.InvalidCredentialsException' occurred in
Google.GData.Client.dll"
at foreach loop
my code is:
private void getsearch(string serchFor)
{
YouTubeRequestSettings setting = new YouTubeRequestSettings("youtubesearch", "APIkey","ise34857#gmail.com","password for my email");
YouTubeRequest Request = new YouTubeRequest(setting);
YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);
query.OrderBy = "viewCount";
query.Query = serchFor;
query.SafeSearch = YouTubeQuery.SafeSearchValues.Moderate;
Feed<Video> videofeed = Request.Get<Video>(query);
videoLookUp = new Dictionary<string, string>();
foreach (Video v in videofeed.Entries)
{
if (v.Media.Content!=null)
{
Console.WriteLine(v.Title);
Console.WriteLine(v.Media.Content.Url);
comboBox1.Items.Add(v.Title);
videoLookUp.Add(v.Title,v.Media.Content.Url);
}
}
}
Please check object setting if my parameter is right and tell me if I had any proplem in my code
Although the YouTube Data API (v2) has been officially deprecated, you can check in this documentation on how to properly authenticate your application using .NET client library. It also shows here how to properly use the YouTubeRequestSettings object.
To perform any operation using the YouTube API, you create a YouTubeRequestSettings object, which specifies the authentication information and authentication scheme to be used. With that object, you then create a YouTubeRequest object that you will use to actually perform the operations. (If you do not specify authentication information when creating the YouTubeRequestSettings object, then you will only be able to use the YouTubeRequest object to perform operations that do not require authentication.
YouTubeRequestSettings settings =
new YouTubeRequestSettings("example app", clientID, developerKey);
YouTubeRequest request = new YouTubeRequest(settings);
For more information and sample code, check this tutorial.
I'm writing a web app that pulls events data from Facebook, and I can get a lot of the information using an app token, but not the picture, which requires a client token, as documented here: https://developers.facebook.com/docs/graph-api/reference/v2.2/event/picture
I want the code that grabs the event data to run automatically on a server at regular intervals, without requiring a user to log in to their Facebook account.
Is there a way I can get a client token without user intervention? If not, is there another way I can get the event picture?
This is the code I am using to get the event data, using C# and JSON.Net (This gets a list of events created by the specified user - ResortStudios):
var fb = new FacebookClient();
dynamic result = fb.Get( "oauth/access_token", new
{
client_id = "XXXXXXXXXXX",
client_secret = "XXXXXXXXXXXXXXXXXXXXXXXXX",
grant_type = "client_credentials"
} );
var apptoken = result.access_token;
fb = new FacebookClient(apptoken);
result = fb.Get("ResortStudios/events");
JObject events = JObject.Parse(result.ToString());
JArray aEvents = (JArray)events["data"];
string s = aEvents.ToString();
List<fbEvent> lEvents = JsonConvert.DeserializeObject<List<fbEvent>>(s);
I've not tried this but something occurred to me that might work for you. Have you considered something like storing it a non-persistent data store like session state? Then, using the Facebook SDK for .NET, you create an ActionResult for UserInfo, like below. (I know this isn't directly applicable but I hoped it might get you thinking.)
//http://facebooksdk.net/docs/web/ajax-requests/
public ActionResult UserInfo()
{
var accessToken = Session["AccessToken"].ToString();
var client = new FacebookClient(accessToken);
dynamic result = client.Get("me", new { fields = "name,id" });
return Json(new
{
id = result.id,
name = result.name,
});
}
I have a Facebook reply as follows:
dynamic response = client.Get("me", new { fields = "verified, picture" });
BELOW IS THE JSON IN 'response'
{"verified":true,
"picture":{"data":{"url":"https://www.abc.com","is_silhouette":true}}}
How do I access the 'url' value in the subkey of 'picture'? Here's what I tried but it fails:
fbPicture = response["picture.data.url"].toString();
I've tried different syntax but to no avail and I've also looked around but to no avail.
Thanks in advance !
The Facebook C# SDK implements an object called JsonObject.
So the easiest would be to cast the returnvalue (in JSON) to the JsonObject.
In your case this should be something like:
<!-- language-all: C# -->
dynamic response = client.Get("me", new { fields = "verified, picture" });
string url = response.picture.data.url;
I'm not entirely sure which Json library you are using, but perhaps try this:
fbPicture = response["picture"]["data"]["url"].ToString();
I'm trying to create a simple iFrame custom tab on my fan page. I'm using the Facebook C# SDK and I need to read the signed_request value that Facebook passes to my iFrame page.
I can print the signed_request encoded value so I know its showing up, but when I try to decode it with the Facebook C# SDK I'm getting an error. I'm using .NET 4.0 and dynamics.
Here's my code:
signedRequestString contains the Request value with the signed_param passed from Facebook.
var result = FacebookSignedRequest.Parse(FacebookContext.Current.AppSecret, signedRequestString);
dynamic signedRequestJson = result.Data;
dynamic page = signedRequestJson.page;
And the error I receive:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at DecodeSignedRequest(String signedRequestString)
Any thoughts why I would be getting a null? I setup my web.config properly (I think), but I'm guessing I'm missing an initialization step or something.
It's easier to use FacebookWebContext.Current.SignedRequest.
You can then access the information about the page:
if (FacebookWebContext.Current.SignedRequest != null)
{
dynamic data = FacebookWebContext.Current.SignedRequest.Data;
if (data.page != null)
{
var pageId = (String)data.page.id;
var isUserAdmin = (Boolean)data.page.admin;
var userLikesPage = (Boolean)data.page.liked;
}
else
{
// not on a page
}
}
You need to cast your signedRequestJson object to an IDictionary key/value pair before you can grab the page data.
You can do this as follows:
dynamic signedRequestJson = result.Data;
var RawRequestData = (IDictionary<string, object>)signedRequestJson;
You can then access the page data using the JSON keys (assuming you are referencing the Newtonsoft.Json.dll library):
Facebook.JsonObject RawPageData = (Facebook.JsonObject)RawRequestData["page"];
currentFacebookPageID = (string)RawPageData["id"];
Hope this helps.
I am using this. I hope it works for you:
Facebook.FacebookConfigurationSection s = new FacebookConfigurationSection();
s.AppId = 'ApplicationID';
s.AppSecret = 'ApplicationSecret';
FacebookWebContext wc = new FacebookWebContext(s);
dynamic da = wc.SignedRequest.Data;
dynamic page = da.page;
string pageid = page.id;
bool isLiked = page.liked;
bool isAdmin = page.admin;