Auth0 Facebook Graph cant get email - c#

I have the following code that supposedly gets the users "email". "fistname", "lastname", "id" and "gender":
var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?fields=first_name,last_name,gender,email"), null, eventArgs.Account);
var response = await request.GetResponseAsync();
var obj = JObject.Parse(response.GetResponseText());
var id = obj["id"].ToString().Replace("\"", "");
var firstname = obj["first_name"].ToString().Replace("\"", "");
var lastName = obj["last_name"].ToString().Replace("\"", "");
var gender = obj["gender"].ToString().Replace("\"", "");
var email = obj["email"].ToString().Replace("\"", "");
I am able to get every thing properly except the email field, which is null. Am i treating the string wrongly, or is my Uri incorrect to begin with ?

Related

Pre-Filled/Sender's Tabs on a Template

I have a sender's/pre-filled tab inside a template. I'm trying to send this template using C# api. Now I'm using the below code to fill this tab while sending a envelope using this template
`var env = new EnvelopeDefinition { TemplateId = templateId };
var prefillTabs = new PrefillTabs()
{
TextTabs = new List<Text>()
{
new Text()
{
DocumentId = "1",
TabLabel = "business-details.BusinessInformation.BusinessName",
Value = "PreFill: BusinessName"
}
}
};
var tabs = new Tabs()
{
PrefillTabs = prefillTabs
};
var signerRole = new TemplateRole
{
Email = signer.Email,
Name = signer.Email,
RoleName = templateRoleName,
Tabs = tabs
};
env.TemplateRoles = new List<TemplateRole> { signerRole };
env.Status = "sent";
// send this envelop using EnvelopApiClient
await envelopesApi.CreateEnvelopeAsync(accountId, env);`
Envelop is sent but the problem is prefilled tab is not populated and also SignHere field is not visible in the sent envelope. I have spent a lot of time figuring it out but couldn't figure it out. Any help will be much appreciated.
DocuSign pre-fill tabs are NOT associated with a recipient or a role. So the code you have cannot work because you have them assigned to the recipient (role) in your template.
What you need to do is either:
Create the fields/tabs you want in the template itself. They will be passed to any envelope created from the template. (Downside - every envelope created from this template will have them).
Add the prefill fields with code like this after the envelope is already created (Downside - need two API calls instead of one):
[![enter image description here][2]][2]
var apiClient = new ApiClient(basePath);
apiClient.Configuration.DefaultHeader.Add(
"Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
PrefillTabs prefillTabs = new PrefillTabs();
prefillTabs.TextTabs = new List<Text>();
prefillTabs.TextTabs.Add(
new Text { PageNumber = "1", DocumentId = "1", Value = "MyValue" });
Tabs tabs = new Tabs();
tabs.PrefillTabs = prefillTabs;
envelopesApi.CreateDocumentTabs(accountId, envelopeId, "1", tabs);

Paypal API - GetVerifiedStatus C#

I tried both 'Sandbox' and 'Live' and that didn't change anything.
ACK code is giving "Failure" & as for the "accountStatus" It's giving me (same goes with CountryCode & UserInfo fields) :
Object reference not set to an instance of an object.
Here is the code and I'm using PayPal Adaptive Accounts SDK btw :
Dictionary<string, string> config = new Dictionary<string, string>();
config.Add("mode", "live");
config.Add("account1.apiUsername", "xxxxxx_api1.outlook.com");
config.Add("account1.apiPassword", "BDxxxxxxVMH8CC422");
config.Add("account1.apiSignature", "AnUrp2fCnv5wuh1OOXxxxxxxtsA4ek2pihCAfCZodv21T9TY6Yidln");
AdaptiveAccountsService service = null;
GetVerifiedStatusResponse resp = null;
GetVerifiedStatusRequest getVerifiedStatusRequest = new GetVerifiedStatusRequest
{
emailAddress = "xxxxxx#outlook.com",
firstName = "MyName",
lastName = "MyLastName",
matchCriteria = "NAME"
};
service = new AdaptiveAccountsService(config);
resp = service.GetVerifiedStatus(getVerifiedStatusRequest);
TextBox1.Text = resp.responseEnvelope.ack.ToString() + resp.accountStatus.ToString();

Get Posts (Wall Facebook) of me and my friends

I use
https://developers.facebook.com/tools/access_token/
I create an App. I want get Posts of the wall of me and my friends.
I try me/feed and me/posts but I get nothing.
I have this unit test.
Any suggestions?
[TestMethod]
public void Basic_using_SDK()
{
// http://blog.prabir.me/posts/facebook-csharp-sdk-making-requests
var fb = new Facebook.FacebookClient();
var result = (IDictionary<string, object>)fb.Get("4");
var id = (string)result["id"];
var name = (string)result["name"];
var firstName = (string)result["first_name"];
var lastName = (string)result["last_name"];
var link = (string)result["link"];
var username = (string)result["username"];
var gender = (string)result["gender"];
var male = (string)result["locale"];
var parameters = new Dictionary<string, object>();
parameters["fields"] = "id,name";
result = (IDictionary<string, object>)fb.Get("4", parameters);
id = (string)result["id"];
name = (string)result["name"];
dynamic result2 = fb.Get("4");
id = result2.id;
name = result2.name;
firstName = result2.first_name;
lastName = result2.last_name;
link = result2.link;
username = result2.username;
gender = result2.gender;
male = result2.locale;
dynamic parameters2 = new ExpandoObject();
parameters2.fields = "id,name";
dynamic result3 = fb.Get("4", parameters);
id = result3.id;
name = result3.name;
dynamic me = fb.Get("zuck");
firstName = me.first_name;
lastName = me.last_name;
var client = new FacebookClient(AccessToken);
dynamic me2 = client.Get("me");
string aboutMe = me2.about;
dynamic result4 = client.Get("/me/feed");
foreach (dynamic post in result4.data)
{
var fromName = post.from.name;
Console.WriteLine(fromName);
}
dynamic result5 = client.Get("/me/posts");
for (int i = 0; i < result5.Count; i++)
{
}
// https://www.facebook.com/profile.php?id=xxxxxxx
// https://graph.facebook.com/xxxxxxx
var uidKiquenet = "xxxxx";
var query = string.Format(#"SELECT status_id,message,time,source,uid,place_id
FROM status WHERE uid IN (SELECT uid FROM status WHERE uid = '" + uidKiquenet + "') ORDER BY time DESC");
dynamic parameters6 = new ExpandoObject();
parameters6.q = query;
dynamic results6 = fb.Get("/xxxxx?fields=id,name,age_range,about,email,first_name,gender");
string myMessage = "Hello from Test";
fb.PostTaskAsync("me/feed", new { message = myMessage }).ContinueWith(t =>
{
if (!t.IsFaulted)
{
string message = "Great, your message has been posted to you wall!";
Console.WriteLine(message);
}
});
fb.GetTaskAsync("me").ContinueWith(t =>
{
if (!t.IsFaulted)
{
var result11 = (IDictionary<string, object>)t.Result;
string myDetails = string.Format("Your name is: {0} {1} and your Facebook profile Url is: {3}",
(string)result11["first_name"], (string)result11["last_name"],
(string)result11["link"]);
Console.WriteLine(myDetails);
}
});
// This uses Facebook Query Language
// See https://developers.facebook.com/docs/technical-guides/fql/ for more information.
query = string.Format("SELECT uid,name,pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0}) ORDER BY name ASC", "me()");
fb.GetTaskAsync("fql", new { q = query }).ContinueWith(t =>
{
if (!t.IsFaulted)
{
var result1 = (IDictionary<string, object>)t.Result;
var data = (IList<object>)result1["data"];
var count = data.Count;
var message = string.Format("You have {0} friends", count);
Console.WriteLine(message);
foreach (IDictionary<string, object> friend in data)
Console.WriteLine((string)friend["name"]);
}
});
}
You must authorize with the correct permission in order to get access to feed posts. Try authorizing with user_posts, as it is explained in the docs: https://developers.facebook.com/docs/graph-api/reference/v2.3/user/feed#read
Be aware that this does not get you access to posts of friends, unless they posted on the wall of the authorized user.
About review, you may want to read this: https://developers.facebook.com/docs/facebook-login/review/faqs#what_is_review
Btw, FQL is deprecated and will only work in v2.0 Apps - not in newer ones.
Same thing happened to me . Here is my Solution
I made my project registered on Facebook developer console. Then I did my code same as you but could not get posts / information . After some time i submitted my application for app review to facebook team (it was still in early development phase) and after their feedback I got my code working . So pending Application review can be your issue also . This option is available in application setting . Give it a shot
Update
Another code sample is here
if (Request["code"] == null)
{
Response.Redirect(string.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
FB_app_id, Request.Url.AbsoluteUri, FB_scope));
return false;
}
else
{
Dictionary<string, string> tokens = new Dictionary<string, string>();
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}&perms=status_update"
, FB_app_id, Request.Url.AbsoluteUri, FB_scope, Request["code"].ToString(), FB_secret_id);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader rd = new StreamReader(response.GetResponseStream());
string vals = rd.ReadToEnd();
foreach (string token in vals.Split('&'))
{
tokens.Add(token.Substring(0, token.IndexOf('=')), token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf('=') - 1));
}
string access_token = tokens["access_token"];
Session["fb_access_token"] = access_token;
return true;
}
}

serialize object to json .NET

I have to serialize object to json string. This is my code:
var addData = new {
nick = user.UserName,
imie = user.Firstname,
nazwisko = user.Surname,
wojewodztwo = user.State
};
var tempUser = new
{
email = user.Email,
list = "12212",
state = 1,
confirm = 0,
custom_fields = addData
};
(...)
var serializer = new JavaScriptSerializer();
PostData = serializer.Serialize(tempUser);
This is result:
"{\"email\":\"testowy#aa.pl\",\"list\":\"12212\",\"state\":1,\"confirm\":0,\"custom_fields\":{\"nick\":\"JakisNicvk\",\"imie\":\"Marian\",\"nazwisko\":\"Mariański\",\"wojewodztwo\":\"małopolskie\"}}"
It looks awfull. How can I generate json string like this, without \? (and where main object has array with custom_fields)?
{"email":"22#aa.pl","list":"12212","custom_fields":{"personalization_tag_1":"value
1","personalization_tag_2":"value 2"}}
Regards.

Handle SkyBiometry API

i need to compare 2 photos similarity. For example picture of son and father and return a percentage of their similarity. I use for SkyBiometry.Client.FC. Something wrong with results returned by API. In all cases of recognizing i get 60%-68% of similarity(threshold).
Finally i tried to compare two same pictures and get result of 54%. I'm confused.What i do wrong? This is my code:
var client = new FCClient("my client id", "my client secret");
var path = Server.MapPath("~/Content/Upload/1");
var ids = new List<string> { "my client id" };
var urls = new List<string>();
Stream firstPicStream = System.IO.File.OpenRead(Path.Combine(path, "me.jpg"));
Stream secondPicStream = System.IO.File.OpenRead(Path.Combine(path, "me.jpg"));
var result1 = client.Faces.EndDetect(client.Faces.BeginDetect(null, new Stream[] { firstPicStream }, Detector.Aggressive, Attributes.Default, null, null));
var result2 = client.Faces.EndDetect(client.Faces.BeginDetect(null, new Stream[] { secondPicStream }, Detector.Aggressive, Attributes.Default, null, null));
urls.Add(result1.Photos[0].Url);
urls.Add(result2.Photos[0].Url);
var tags1 = result1.Photos[0].Tags;
var tags2 = result2.Photos[0].Tags;
var tagsIds = tags1.Select(tag => tag.TagId).ToList();
tagsIds.AddRange(tags2.Select(tag => tag.TagId));
var tagSaveResponce = client.Tags.EndSave(client.Tags.BeginSave(tagsIds, "My Namespace", "label", null, null));
var recognizeResult = client.Faces.EndRecognize(client.Faces.BeginRecognize(ids, urls, null, "My Namespace", Detector.Aggressive, Attributes.Default, null, null));
Did you call faces/train after tags/save for the user you save new tags for? Because if you don't you will perform recognition with old user tags only.
Also note that user id can not have spaces, make sure you check FCResponse.Status property for possible errors.

Categories

Resources