Get Access Token programmatically in Unit Test Method - c#

First, I open Facebook Developers page, and I create new App. ( I get AppID, AppSecret values)
I want create Unit Test method for do Post to the wall, and later delete the post.
publish_stream, publish_actions
Manually, I do this 3 steps
Open url
https://graph.facebook.com/oauth/authorize?client_id=xxxxx&redirect_uri=http://www.kiquenet.com/&scope=publish_stream,publish_actions
Then, this url opened, and I get the code value:
http://www.kiquenet.com/?code=A....3qhOw#=
And then, open this url and I get the access token value:
https://graph.facebook.com/oauth/access_token?client_id=xxxxx&redirect_uri=http://www.kiquenet.com/&scope=publish_stream,publish_actions&client_secret=zzzzz&code=A...3qhOw#=
Finally, I get the access token:
const string token = "C...SNo";
My code now is for my unit test is working. Only I need do the delete.
using Facebook;
[TestMethod]
public void Post_to_the_wall()
{
var client = new FacebookClient(token);
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article";
parameters.link = "http://www.example.com/article.html";
parameters.picture = "http://www.example.com/article-thumbnail.jpg";
parameters.name = "Article Title";
parameters.caption = "Caption for the link";
parameters.description = "Longer description of the link";
parameters.actions = new
{
name = "View on Zombo",
link = "http://www.zombo.com",
};
parameters.privacy = new
{
value = "ALL_FRIENDS",
};
dynamic result = client.Post("me/feed", parameters);
// TODO: NOW, delete the post ???
}
How can I do programmatically the 3 Manually steps ?

Related

How to use SMS-Authentication in DocuSign

I'm trying to implement the SMS authentication with the aid of the DocuSign-SDK library.
var signer = new Signer {...};
signer.RequireIdLookup = "true";
signer.IdCheckConfigurationName = "SMS Auth $";
signer.SmsAuthentication = new RecipientSMSAuthentication {
SenderProvidedNumbers = new List<string> {
"0171*******"
}
};
When I try to send this envelope to the DocuSign API it will reply with the following error message:
Error calling CreateEnvelope:
{"errorCode":"INVALIDAUTHENTICATIONSETUP","message":"Recipient phone
number is invalid. Phone number for SMS Authentication: provided is
invalid. }
INVALIDAUTHENTICATIONSETUP: Authentication is not setup correctly for the recipient.
Is there something I have to enable on the DocuSign Admin page? I couldn't find any feature or something like that I need to enable.
Did I implement it the wrong way? Maybe someone can give me some suggestions.
Thanks
BTW: The given phone number should be valid.
EDIT:
When I'm using the new method as #Inbar wrote, I can't get the needed workflowId from the AccountsApi.
var client = new ApiClient(ApiClient.Demo_REST_BasePath);
var token = "eyJ1...";
client.Configuration.DefaultHeader.Add("Authorization", "Bearer " + token);
var accountsApi = new AccountsApi(client);
var response = accountsApi.GetAccountIdentityVerification(accountId);
var result = response.IdentityVerification; // Is empty. Why?
It seems that I have no IdentityVerification options which I can use for the authentication.
How can I enable such IdentityVerification options?
Or what else do I need to pay attention to?
Your code is using the older method, the new method code is provided in GitHub, I'll post it here too. You can find the article on Dev Center.
string workflowId = phoneAuthWorkflow.WorkflowId;
EnvelopeDefinition env = new EnvelopeDefinition()
{
EnvelopeIdStamping = "true",
EmailSubject = "Please Sign",
EmailBlurb = "Sample text for email body",
Status = "Sent"
};
byte[] buffer = System.IO.File.ReadAllBytes(docPdf);
// Add a document
Document doc1 = new Document()
{
DocumentId = "1",
FileExtension = "pdf",
Name = "Lorem",
DocumentBase64 = Convert.ToBase64String(buffer)
};
// Create your signature tab
env.Documents = new List<Document> { doc1 };
SignHere signHere1 = new SignHere
{
AnchorString = "/sn1/",
AnchorUnits = "pixels",
AnchorXOffset = "10",
AnchorYOffset = "20"
};
// Tabs are set per recipient/signer
Tabs signer1Tabs = new Tabs
{
SignHereTabs = new List<SignHere> { signHere1 }
};
string workflowId = workflowId;
RecipientIdentityVerification workflow = new RecipientIdentityVerification()
{
WorkflowId = workflowId,
InputOptions = new List<RecipientIdentityInputOption> {
new RecipientIdentityInputOption
{
Name = "phone_number_list",
ValueType = "PhoneNumberList",
PhoneNumberList = new List<RecipientIdentityPhoneNumber>
{
new RecipientIdentityPhoneNumber
{
Number = phoneNumber,
CountryCode = countryAreaCode,
}
}
}
}
};
Signer signer1 = new Signer()
{
Name = signerName,
Email = signerEmail,
RoutingOrder = "1",
Status = "Created",
DeliveryMethod = "Email",
RecipientId = "1", //represents your {RECIPIENT_ID},
Tabs = signer1Tabs,
IdentityVerification = workflow,
};
Recipients recipients = new Recipients();
recipients.Signers = new List<Signer> { signer1 };
env.Recipients = recipients;
I've created a new developer account on DocuSign and created a small test app in order to request identity verification options. Fortunately, that was working now and I got all available options but I do not understand why this is not working for my other developer account ("old").
When I compare both accounts I don't see the "Identity Verification" setting in the "old" account.
It is possible to activate this "Identity Verification" setting for my "old" dev account?
I guess that enabling this feature would solve the problem.
EDIT:
Ok, I've solved the problem.
I figured out that no IDV was configured for my developer account. In that case, the identity_verification call will return an empty array.
see: https://developers.docusign.com/docs/esign-rest-api/how-to/id-verification/
Also, I have read the following note in the DocuSign documentation:
Note: Phone authentication may not be enabled for some older developer
accounts. If you cannot choose to use phone authentication for your
account, contact support to request access. see:
https://developers.docusign.com/docs/esign-rest-api/esign101/concepts/recipients/auth/#id-verification-idv
So I contacted DocuSign support and they give me access to the IDV accordingly.
Now it is working fine.

Support additional fields as tags for Tumblr search...

I am trying to find a way to add the submission of someone's name to the search function. I need to send the name as a tag, but the issue is on the display end.
You can see the site here - http://southu.tumblr.com/ You will need a password - test123
The tag is displayed above the video. The current tags are "Commitment" and "Sacrifice". The name is separate so it can be displayed in a different spot. Tumblr doesn't inherently allow for defining between different tags on the display side.
Basically, I need to support both fields as tags, but not display the name in the tag display (above the video)
Here is the C# from the VideoSubmissionController.cs file.
// Posts the video submission using the TumblrApi.
private void SendToTumblr(VideoSubmission videoSubmission)
{
string consumerKey = ConfigurationManager.AppSettings.Get("TumblrConsumerKey");
string consumerSecret = ConfigurationManager.AppSettings.Get("TumblrConsmerSecret");
string oauthToken = ConfigurationManager.AppSettings.Get("TumblrOauthTokenKey");
string oauthVerifier = ConfigurationManager.AppSettings.Get("TumblrOauthTokenSecret");
Token token = new Token(oauthToken, oauthVerifier);
var client_factory = new TumblrClientFactory();
using (var client = client_factory.Create<TumblrClient>(consumerKey, consumerSecret, token))
{
//string body = "This post was created through the api";
//string title = "Testing API Push";
string[] tags = new string[] { videoSubmission.Question.QuestionText };
//create the data for a text post: use PostData.CreateText
var postData = PostData.CreateVideo(videoSubmission.VideoUrl, videoSubmission.Name, tags);
//create the post: pass the name of the blog where to post to
var postTask = client.CreatePostAsync(ConfigurationManager.AppSettings.Get("TumblrUrl"), postData);
postTask.Wait();
var postResult = postTask.Result;
videoSubmission.TumblrId = postResult.PostId.ToString();
db.Entry(videoSubmission).State = EntityState.Modified;
db.SaveChanges();
}
}

Delete Post of Wall Facebook using SDK C#

I newbie using Facebook SDK for C#
I have seen this post to wall in unit test.
Get Access Token programmatically in Unit Test Method
Now, I want to delete post in my wall.
using Facebook;
[TestMethod]
public void Post_to_the_wall()
{
var client = new FacebookClient(token);
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article";
parameters.link = "http://www.example.com/article.html";
parameters.picture = "http://www.example.com/article-thumbnail.jpg";
parameters.name = "Article Title";
parameters.caption = "Caption for the link";
parameters.description = "Longer description of the link";
parameters.actions = new
{
name = "View on Zombo",
link = "http://www.zombo.com",
};
parameters.privacy = new
{
value = "ALL_FRIENDS",
};
dynamic result = client.Post("me/feed", parameters);
// TODO: NOW, delete the post ???
}
Any suggestions ?
Simply do this:
dynamic result = client.Post("me/feed", parameters);
client.Delete(result.id);
Post method get Postid (id property), and you can use it for delete the post.
https://developers.facebook.com/docs/graph-api/reference/v2.2/post
An app can delete a post if it published it
Check out the example code on that page. You need a User Token with publish_actions to make a DELETE request to /post-id.

Rally API: Adding Users to a Project

I'm new to the Rally world and am struggling through how to use the RallyRestAPI. There are a number of examples of how to query Rally to get back pertinent information that I have found most helpful. What I'm trying to do is create a C# command line tool to add users to a project. It appears that I use the RallyRestAPI.Create("projectpermission",some dynamic json object) interface to accomplish the creation. My problem is understanding the "some dynamic json object" part. I'm not sure how to correctly set it up. If someone has a small example of how to set it up, I would appreciate it.
Here's a code sample illustrating how to do this. Note that:
UserID running the code to create permissions must be a Workspace or Subscription Administrator
User must already have permissions in the Workspace (i.e be a Workspace User) in order for the ProjectPermission creation to succeed
namespace RestExample_AddUsersToProject {
class Program
{
static void Main(string[] args)
{
String userName = "user#company.com";
String userPassword = "topsecret";
String serverUrl = "https://rally1.rallydev.com";
String wsapiVersion = "1.38";
RallyRestApi restApi = new RallyRestApi(
userName,
userPassword,
serverUrl,
wsapiVersion
);
restApi.Headers[RallyRestApi.HeaderType.Vendor] = "Rally Software";
restApi.Headers[RallyRestApi.HeaderType.Name] = "RestExample_AddUsersToProject";
// Query for Project for which we want to add permissions
Request projectRequest = new Request("project");
projectRequest.Fetch = new List<string>()
{
"Name",
"Owner",
"State",
"Description"
};
String projectName = "Avalanche Hazard Mapping";
projectRequest.Query = new Query("Name", Query.Operator.Equals, projectName);
QueryResult queryProjectResults = restApi.Query(projectRequest);
var myProject = queryProjectResults.Results.First();
String myProjectReference = myProject["_ref"];
Console.WriteLine("Project Name: " + myProject["Name"]);
Console.WriteLine("State: " + myProject["State"]);
// Query for User for whom we wish to add ProjectPermission
Request userRequest = new Request("user");
userRequest.Fetch = new List<string>()
{
"UserName",
"Subscription",
"DisplayName"
};
// User needing the permissions
userRequest.Query = new Query("UserName", Query.Operator.Equals, "\"boromir#midearth.com\"");
QueryResult queryUserResults = restApi.Query(userRequest);
var myUser = queryUserResults.Results.First();
String myUserReference = myUser["_ref"];
Console.WriteLine("Username: " + myUser["UserName"]);
Console.WriteLine("Display Name: " + myUser["DisplayName"]);
Console.WriteLine("Subscription: " + myUser["Subscription"]);
// Setup required ProjectPermission data
DynamicJsonObject newProjectPermission = new DynamicJsonObject();
newProjectPermission["User"] = myUser;
newProjectPermission["Project"] = myProject;
newProjectPermission["Role"] = "Editor";
// Create the permission in Rally
CreateResult addProjectPermissionResult = restApi.Create("ProjectPermission", newProjectPermission);
DynamicJsonObject fetchedProjectPermission = restApi.GetByReference(addProjectPermissionResult.Reference, "Name");
Console.WriteLine("Created ProjectPermission with Role: " + fetchedProjectPermission["Name"]);
}
}
}
There are some very basic examples of CRUD + querying here:
http://developer.rallydev.com/help/rest-api-net
The general flow will always be to create a new DynamicJsonObject, set the appropriate fields and then pass that object to the Create method of an RallyRestApi.

How to publish a post with multiple attachments to a user's facebook profile?

My facebook app uses the Facebook C# SDK to publish to a user's Facebook profile. I'm currently publishing multiple posts with one attachment, but I'd much rather publish one summary post with multiple attachments. I've done this with the JavaScript API, but is it possible with the C# SDK?
This is my current publish code:
FacebookApp app = new FacebookApp(user.AccessToken);
string userFeedPath = String.Format("/{0}/feed/", user.FacebookUserId);
string message = String.Format("{0} earned an achievement in {1}",
user.SteamUserId, achievement.Game.Name);
dynamic parameters = new ExpandoObject();
parameters.link = achievement.Game.StatsUrl;
parameters.message = message;
parameters.name = achievement.Name;
parameters.description = achievement.Description;
parameters.picture = achievement.ImageUrl;
app.Api(userFeedPath, parameters, HttpMethod.Post);
We currently don't support multiple attachments. As far as I know you can't publish multiple attachments with either the graph or rest api. If you have a sample that shows how to do it, I will get it implemented in the SDK.
i have the same code as yours but it doesent work for me. I am trying this:
public void plesni()
{
try
{
dynamic parameters = new ExpandoObject();
parameters.message = "xxxxxxx";
parameters.link = "xxxxxxxx";
// parameters.picture=""
parameters.name = "xxxxxx";
parameters.caption = "xxxxxxx";
parameters.description = "xxxxxxxxxx";
parameters.actions = new
{
name = "xxxxxxx",
link = "http://www.xxxxxxxxxxxxxx.com",
};
parameters.privacy = new
{
value = "ALL_FRIENDS",
};
parameters.targeting = new
{
countries = "US",
regions = "6,53",
locales = "6",
};
dynamic result = app.Api("/uid/feed/", parameters, HttpMethod.Post);
// app.Api("/uid/feed", parameters);
Response.Write("Sucess");
}
catch (FacebookOAuthException)
{
Response.Write("...... <br/>");
}
}
if instead of uid I put me it works fine.
I am hoping for your help.
Have a good day.

Categories

Resources