Passing parameters to Facebook Open Graph API - c#

I'm trying to upload a video to the Facebook open graph using the C# SDK. The video seems to upload fine and I get an Id for the activity, but only the sample metadata appears.
After a little digging, I found this:
Before being able to publish an Open Graph action for a user and having define its corresponding connected object type in Step 3, you will now need to create a publicly accessible web page that represents this object using Open Graph metatags. Once this object page is created, you can use the Graph API to publish an action.
Since this is a client-side app, I don't have a web page that I can refer Facebook to. So how do I pass in the right parameters?
Here's my code:
var parameters = new Dictionary<string, object>();
parameters["source"] = new FacebookMediaObject { ContentType = "video/mpeg", FileName = "video.mpeg" }.SetValue(File.ReadAllBytes(#"D:\sample video.MP4"));
parameters["og:title"] = "Sample video";
parameters["title"] = "Sample video";
parameters["og:description"] = "Test description";
parameters["highlight"] = "http://samples.ogp.me/287287444686523"; // If I don't put this, the upload fails
fb.PostAsync("/me/myobjectname:share", parameters);
Thanks!

For version 6, you can do:
var fb = new FacebookClient(accessToken);
string attachementPath = #"C:\image.jpg";
using (var stream = File.OpenRead(attachementPath))
{
dynamic result = fb.Post("me/photos",
new
{
message = "upload using Facebook C# SDK",
file = new FacebookMediaStream
{
ContentType = "image/jpg",
FileName = Path.GetFileName(attachementPath)
}.SetValue(stream)
});
}
More details here.

Related

Apply Template using .NET SDK

I'm trying to apply a template (not use a template) using the .NET SDK and I can't seem to get it. I have seen one or two other articles on here but neither is using the SDK. Can anyone help me solve this using the SDK?
My situation is this: I have a template defined that contains all of my anchor tags with placement info. When I apply the template via the UI, it works fine and the tags get placed appropriately. When I upload the same document via the API, the tags are not applied.
I have tried to replicate what is shown in these articles using Composite Templates with no success:
How do I apply a server template to envelope document in DocuSign API?
Docusign API - Create envelope, apply template, prefill values
In one of the articles, the OP said the envelope needed to be a Draft. I tried that, but then I haven't been able to change it to "sent" after that.
Here's some of the relevant code from my ASP.NET Web Forms test project. In this project, I'm using a asp:FileUpload control to grab the file contents and then I call the SendFileToDocusign() method:
private void SendFileToDocusign(byte[] fileData, string accessToken)
{
//Create a signer recipient to sign the document, identified by name and email
//We set the clientUserId to enable embedded signing for the recipient
Signer tmpSigner1 = new Signer {
Email = "me#me.com", Name = "Test Tester",
ClientUserId = "1000", RecipientId = "1", RoleName = "Signer1", CustomFields = new List<string> { "Buyer1" }
};
//Step 1. Create the envelope definition
EnvelopeDefinition tmpEnvDef = MakeEnvelopeAndApplyTemplate(fileData, new List<Signer> { tmpSigner1 });
//Step 2. Call DocuSign to create the envelope
ApiClient tmpClient = new ApiClient(DOCUSIGN_API_BASEPATH);
tmpClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi tmpEnvelopesApi = new EnvelopesApi(tmpClient);
EnvelopeSummary tmpResults = tmpEnvelopesApi.CreateEnvelope(DOCUSIGN_ACCOUNTID, tmpEnvDef);
string tmpEnvelopeID = tmpResults.EnvelopeId;
//Step 3. create the recipient view, the Signing Ceremony
RecipientViewRequest tmpViewRequest = MakeRecipientViewRequest(tmpSigner1);
//call the CreateRecipientView API
ViewUrl tmpRecipView = tmpEnvelopesApi.CreateRecipientView(DOCUSIGN_ACCOUNTID, tmpEnvelopeID, tmpViewRequest);
Response.Redirect(tmpRecipView.Url);
}
private EnvelopeDefinition MakeEnvelopeAndApplyTemplate(byte[] fileData, List<Signer> signers)
{
EnvelopeDefinition tmpEnv = new EnvelopeDefinition(EmailSubject:"We don't really use the Subject Line here");
Document tmpDoc = new Document();
Recipients tmpRecipients = new Recipients(Signers:signers);
CompositeTemplate tmpCompTemplate = new CompositeTemplate("1");
string tmpfileDataB64 = Convert.ToBase64String(fileData);
tmpDoc.DocumentBase64 = tmpfileDataB64;
tmpDoc.Name = "Test file";//can be different from actual file name
tmpDoc.FileExtension = "pdf";
tmpDoc.DocumentId = "1";
InlineTemplate tmpInlineTemplate = new InlineTemplate();
tmpInlineTemplate.Sequence = "1";
tmpInlineTemplate.Recipients = tmpRecipients;
ServerTemplate tmpServerTemplate = new ServerTemplate("2", DOCUSIGN_TEMPLATE_ID);
tmpCompTemplate.ServerTemplates = new List<ServerTemplate>() { tmpServerTemplate };
tmpCompTemplate.InlineTemplates = new List<InlineTemplate>() { tmpInlineTemplate };
tmpCompTemplate.Document = tmpDoc;
tmpEnv.CompositeTemplates = new List<CompositeTemplate>() { tmpCompTemplate };
//Request that the envelope be sent by setting |status| to "sent".
//To request that the envelope be created as a draft, set to "created"
tmpEnv.Status = "sent";
return tmpEnv;
}
Thanks for any help you can offer.
Your code has to handle the recipients correctly.
The roleName must match between recipients pre-defined in the template and the ones you add in your code.
I don't see in your code that part.
The example you use is for composite template. The relevant code for this is in a regular template example but it's the same.
https://github.com/docusign/code-examples-csharp/blob/master/launcher-csharp/eSignature/Controllers/Eg009UseTemplateController.cs
TemplateRole signer1 = new TemplateRole();
signer1.Email = signerEmail;
signer1.Name = signerName;
signer1.RoleName = "signer";
TemplateRole cc1 = new TemplateRole();
cc1.Email = ccEmail;
cc1.Name = ccName;
cc1.RoleName = "cc";

OAuthException #100 when creating custom object with facebook sharp SDK

Basically, I have a custom object inheriting from place. I am creating a c# tool for creating the objects using the Facebook Sharp c# SDK located here I am using an app access token when making these calls.
I've tried various approaches and variation within:
Here is a sample call that yeilds:
(OAuthException - #100) (#100) The parameter object is required
_api.AccessToken = GetExtendedToken().Token;
var postdata = new Dictionary<string, object>
{
//{"fb:app_id", "appId"},
//{"type", "myapp:myobject"},
{"url", resort.Url},
{"title", resort.Name },
{"image", resort.Image},
{"video", resort.Video},
{"description", resort.Description},
{"place:location:latitude", lat},
{"place:location:longitude", long}
};
var response = _api.Post("/app/objects/myapp:myobject", postdata);
if I uncomment the type parameter I get:
(OAuthException - #2500) Cannot specify type in both the path and query parameter
If I add the type back in, and remove the type from the path, I get
a response of true but this should be something like id:
23049820398092384
If I remove the place objects, or if I remove place and type, or if
I remove place but use the type and change the get path, I still get
errors.
refactored a bit. In this scenario I needed to assign the postdata information to an object as such below. also needed to stop using facebooksharp, their api does weird stuff to the request.
var obj = new
{
app_id = appId,
type = app_name:object_type",
url = Url,
title = Name,
image = Image,
video = Video,
description = Description
};
var vars = new NameValueCollection {{"object", JsonConvert.SerializeObject(obj)}, {"format", "json"}, {"access_token", AppToken}};
var url = "https://graph.facebook.com/app/objects/"+ _appName + object_type;
return HttpTools.Post(url, vars);

facebook upload photo as company page

I have a question regarding using facebook graph API (OAuth) to upload photo.
I have created one company page under my account.
When I use my account to upload photo to my company page, my user name appears as a user who uploaded the page.
Is there anyway I can upload page so that company name appears?
Below is the code that I currently implemented.
string access_token = FacebookSystem.RetrieveToken(UserEmail, AppID);
string query = string.Empty;
if (string.IsNullOrEmpty(PageID) || PageID.Equals("default", StringComparison.InvariantCultureIgnoreCase))
{
query = "me/photos";
}
else
{
query = string.Format("{0}/photos", PageID);
}
var fb = new FacebookClient(access_token);
try
{
dynamic parameters = new ExpandoObject();
foreach (string i in args.FileList)
{
parameters.message = args.Comment;
parameters.source = new FacebookMediaObject
{
ContentType = "image",
FileName = Path.GetFileName(i)
}.SetValue(File.ReadAllBytes(i));
fb.Post(query, parameters);
}
}
in order to use Graph API on behalf of a Page, you need to get Page access token - see here for more details: https://developers.facebook.com/docs/facebook-login/access-tokens/#pagetokens
Authenticate the user and request the manage_pages permission
Get the list of pages the user manages from (1): https://graph.facebook.com/me/accounts?access_token=USER_ACCESS_TOKEN
Parse the list and get the token - and use it to post to the feed.
you will do (1) in graph API explorer - and you will get user token. Then insert that token into URL in (2) - and you will see all your pages and corresponding token. Take the one you need and use it in your C# code to upload images.

Facebook C# SDK WP7 - Can't upload photo to Facebook

I'm trying to upload a photo to facebook using the Facebook C# SDK with WP7.
Here's my code:
public void PostMessageWithImage(string statusMessage, Stream stream)
{
FacebookClient fb = new FacebookClient(AccessToken);
FacebookMediaStream mediaStream = new FacebookMediaStream
{
FileName = DateTime.Now.ToLocalTime().ToLongDateString(),
ContentType = "image/jpeg",
}.SetValue(stream);
fb.PostCompleted += MessagePostCompleted;
fb.PostAsync(this.id + "/photos", new
{
message = statusMessage, //already tried name and caption
source = mediaStream
});
}
I keep getting this:
(OAuthException - #1) (#1) An unknown error occurred
at Facebook.FacebookClient.ProcessResponse(HttpHelper httpHelper, String responseString, Type resultType, Boolean containsEtag, IList`1 batchEtags)
at Facebook.FacebookClient.<>c__DisplayClass4.<ApiAsync>b__1(Object o, OpenReadCompletedEventArgs e)
This code was working fine four months ago, but now I just can't upload photos to Facebook. It only works when I use a url instead of a file. Could you help me?
i got same error.
that my code :
dynamic argumentContent = new ExpandoObject();
argumentContent.message = imageDesc;
if (!string.IsNullOrEmpty(imageUrl))
argumentContent.url = imageUrl;
else
argumentContent.source = new FacebookMediaObject
{
ContentType = "image/jpeg",
FileName = FormatUploadPictureFileName()
}.SetValue(imageBytes);
FacebookClient fbClient = new FacebookClient(accessToken);
fbClient.PostTaskAsync("me/photos", argumentContent);
fbClient.PostCompleted += (postContent, Ex) =>
{});
soluction:
if this image create with your code and format as stream. so you will got this error.
first you need save it as png/jpeg file to isolate storage .
then read it and format to bytes[] array from local isolate storage .
you will found it's work.

Creating an album on a Page

I am trying to post make a album and upload photos to a page on facebook that I have administrative rights to. It works using my facebook account's ID found on Find my facebook ID but it doesn't work when I use my page's ID. This is my code for creating the album.
var facebookClient = new FacebookClient(Properties.Settings.Default.AccessToken);
dynamic parameters = new ExpandoObject();
parameters.name = AlbumName;
parameters.description = AlbumDescription;
parameters.uid = AlbumOwnerID;
var fbResult = facebookClient.Post(string.Format("/{0}/Albums", AlbumOwnerID), parameters);
And this is the error that I get.

Categories