Changing properties on FB's User object - c#

Can I change properties on FB's User object? Can I change "work" and "education"? I need to add information to these collections. I have user_work_history permission all right.
I used CS-Canvas-AspNetWebForms-WithoutJsSdk as a basis. Server replies "true" (in the id variable) but nothing gets changed. "100002852727242" is id on my app's fake test user, Dorothy Ambhebgbgbdb Liman. Tried also post to "me" instead with same effect (= zilch).
Here's my code:
protected void btnPostToWall_Click(object sender, EventArgs e)
{
if (CanvasAuthorizer.Authorize())
{
var fb = this.CurrentClient;
var parameters = new
{
work = new []
{
new
{
employer = new
{
id = "20528438720",
name = "Microsoft"
},
location = new
{
id = "109738839051539",
name = "Redmond, Washington"
},
position = new
{
id = "131108890265554",
name = "SDE"
},
start_date = "1991-01"
}
}
};
try
{
dynamic id = fb.Post("100002852727242", parameters);
lblPostMessageResult.Text = "Message posted successfully";
txtMessage.Text = string.Empty;
}
catch (FacebookApiException ex)
{
lblPostMessageResult.Text = ex.Message;
}
}
}
Original sample code was posting something on the Dorothy's wall, no probs there. Maybe I can't post to "http://graph.facebook.com/me?"? Couldn't find anything useful anywhere. Any ideas?
Thanks in advance!!

Currently, you cannot POST to /USER_ID, only to connections on the User object, e.g. /USER_ID/feed. Hence, you cannot change properties on the User object via a POST.

Related

Writing mutation graphql-client c#

I tried to write mutation but it gives me error.
as {"errors":[{"message":"Syntax Error: Expected $, found Name \"objects\"","locations":[{"line":2,"column":27}],"extensions":{"code":"GRAPHQL_PARSE_FAILED"}}]}
The code I wrote is this.
[HttpGet("GraphDataCreate")]
public async Task<dynamic> ReturnGraphDataCreate()
{
using var graphQLClient = new GraphQLHttpClient("https://api.spacex.land/graphql/", new NewtonsoftJsonSerializer());
var trial = new GraphQLRequest
{
Query = #"
query insert_users(objects: { name: $name, rocket: $rocket }) {
returning {
id
name
rocket
timestamp
twitter
}
}",
OperationName = "insert_users",
Variables = new
{
name = "AdiAntNam",
rocket = "SPUTNIK5V"
}
};
var graphQLResponse = (object)(null);
try
{
graphQLResponse = await graphQLClient.SendQueryAsync<dynamic>(trial);
}
catch (Exception ex)
{
var err = ex;
string err1 = ex.Message;
string err2 = ex.InnerException.Message;
}
return Task.FromResult(graphQLResponse);
}
Now what is it I'm missing in this part ?
The reference I've taken is from here.
https://github.com/graphql-dotnet/graphql-client
The problem with the example is the data type which is written that is hard to follow PersonAndFilms($id: ID) now ID is a data type so I was assuming that it was just a variable name declared that's why I was in confusion.
So I had written it as query insert_users(objects: { name: $name, rocket: $rocket }) which was not understandable for GraphQL as it requires Data Type, so I re-writed my query as below.
var trial = new GraphQLRequest
{
Query = #"
mutation xyz($nameU: String, $rocketU: String)
{
insert_users(objects: { name: $nameU , rocket: $rocketU })
{
returning
{
id
name
rocket
timestamp
twitter
}
}
}",
OperationName = "xyz",
Variables = new
{
nameU = "AdiAntNam2",
rocketU = "SPUTNIK5V"
}
};
Now the mutation xyz($nameU: String, $rocketU: String) it reads correct data type. The example is correct some what in the project but confusing to end user as $id: ID is not much understandable so its better to use example as mine.

Making DialogFlow v2 DetectIntent Calls w/ C# (including input context)

So I finally figured out a way to successfully make detect intent calls and provide an input context. My question is whether or not this is the CORRECT (or best) way to do it:
(And yes, I know you can just call DetectIntent(agent, session, query) but I have to provide a input context(s) depending on the request)
var query = new QueryInput
{
Text = new TextInput
{
Text = model.Content,
LanguageCode = string.IsNullOrEmpty(model.Language) ? "en-us" : model.Language,
}
};
var commonContext = new global::Google.Cloud.Dialogflow.V2.Context
{
ContextName = new ContextName(agent, model.sessionId, "my-input-context-data"),
LifespanCount = 3,
Parameters = new Struct
{
Fields = {
{ "Source", Value.ForString(model.Source) },
{ "UserId" , Value.ForString(model.UserId.ToString())},
{ "Name" , Value.ForString(model.FirstName)}
}
}
};
var request = new DetectIntentRequest
{
SessionAsSessionName = new SessionName(agent, model.sessionId),
QueryParams = new QueryParameters
{
GeoLocation = new LatLng {Latitude = model.Latitude, Longitude = model.Longitude},
TimeZone = model.TimeZone ?? "MST"
},
QueryInput = query
};
request.QueryParams.Contexts.Add(commonContext);
// ------------
var creds = GetGoogleCredentials("myCredentials.json");
var channel = new Grpc.Core.Channel(SessionsClient.DefaultEndpoint.Host, creds.ToChannelCredentials());
var client = SessionsClient.Create(channel);
var response = client.DetectIntent(request);
channel.ShutdownAsync();
return response;
Note: I included the explicit ShutDownAsync (it's not in an async call) because I was getting some file locking issues when attempting to re-deploy the WebAPI project (and only after having executed this code).
Thanks
Chris
Updated 4/25: The most basic way I use this is to integrate the user's name into intent responses:
It can also be read from within the webhook/inline fulfillment index.js:
const name = request.body.queryResult && request.body.queryResult.outputContexts && request.body.queryResult.outputContexts[0].parameters.Name

password data not appear in edit mode

i have a problem
in edit mode i bring user data and all data come normally
then i add that data to text fields on the page and that also work well
I'm sure from that as i see it in debug mode
but when the page come to the browser the password field is empty although i put the data on it
can any one tell me where is the problem ???
that is the code
method get data from data base
public AdminsContianer getContainer(int adminId)
{
using (Naqqab context = new Naqqab())
{
IQueryable<user> admin = getContainer_compiledQuery2.Invoke(context, adminId);
if (admin.Count() > 0)
{
var add = admin.FirstOrDefault();
if (add != null)
{
var rc = new AdminsContianer();
rc.FirstName = add.user_firstname;
rc.adminCreationdate = (DateTime)add.user_creationdate;
rc.LastName = add.user_lastname;
rc.Username = add.user_username;
rc.Password = add.user_password;
rc.adminLuState = add.user_lu_status.ToString();
rc.adminLuType = add.user_lu_type.ToString();
rc.adminLevel = add.admin_level.ToString();
rc.adminId = add.user_id;
return rc;
}
else
{
return null;
}
}
else
{
return null;
}
}
}
method put data in text fields
public void FillFormFields(AdminsContianer ad)
{
HiddenAdminID.Value = AdminIdToEdit;
registerAdminUsername.Text = ad.Username;
registerAdminLastname.Text = ad.LastName;
registerAdminFirstname.Text = ad.FirstName;
registerAdminPassword.Text = ad.Password;
registerAdminCPassword.Text = ad.Password;
adminLevelDropDownList.SelectedValue = ad.adminLevel.ToString();
//userTypeDropDownList.SelectedValue = ad.adminLuType.ToString();
registerAdminState.SelectedValue = ad.adminLuState.ToString();
}
thanks in advance
Use the following code to set value in password textbox registerAdminPasswod.Attributes.Add("value", ad.Password);
Why would you like to show the password because it can't be understand by the user.
Here is a solution its a code project link which has the solution
or
txt1.Text = "sample_password";
if (txt1.TextMode == TextBoxMode.Password)
{
txt1.Attributes.Add("value", txt1.Text);
}

Need a default search engine for web browser control

I have created a web browser app for windows phone 7 using web browser control. I want to add a default search engine(i.e, a textBox that is used for Google search or Bing search). And also if the user type anything(words like technology or so on), the search should be redirected to the above default search engine. Can anyone help me with this???
The textBox that I used for entering URL is named as "UrlTextBox" and my web browser control is named as "browsers". The textBox is used for search engine is named as "SearchTextBox".
Thanks in advance for your hard work!!!
public void browsers_Navigating(object sender, NavigatingEventArgs e)
{
UrlTextBox.Text = e.Uri.ToString();
if (navigationcancelled)
{ e.Cancel = true; }
SearchEngine[] availableSearchEngines = new SearchEngine[]
{new SearchEngine(){ Name = "Google", URLPattern = "http://www.google.com/search?q={0}" }};
new SearchEngine(){ Name = "Yahoo", URLPattern = "http://search.yahoo.com/search?p={0}" };
new SearchEngine(){ Name = "Bing", URLPattern = "http://www.bing.com/search?q={0}" };
}
UrlTextBox-:
private void UrlTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Uri url;
if (Uri.TryCreate(UrlTextBox.Text, UriKind.Absolute, out url))
{
this.urls[this.currentIndex] = UrlTextBox.Text;
this.browsers[this.currentIndex].Navigate(url);
}
if (!Uri.TryCreate(UrlTextBox.Text, UriKind.Absolute, out url))
{
SearchEngine defaultSearchEngine = availableSeachEngines[0];
String URL = String.Format(defaultSearchEngine.URLPattern, UrlTextBox.Text);
}
else
{
Navigate(UrlTextBox.Text);
}
}
}
But there is an error says "availableSeachEngines" --->
The name availableSeachEngines does not exist in the current context.
Now i have added my codes above that i have used in my program and also added Muaz Othman codes into it. But its not working for me and also shows the error. I think am making some mistakes in it. Can anyone correct it??? Thanks in advance!!!
You can create a class like this:
public class SearchEngine {
public string Name {set; get}
public string URLPattern { get; set;}
public override string ToString(){
return Name;
}
}
and in your code you can have this array:
SearchEngine[] availableSearchEngines = new SearchEngine[]{
new SearchEngine(){ Name = "Google", URLPattern = "http://www.google.com/search?q={0}" };
new SearchEngine(){ Name = "Yahoo", URLPattern = "http://search.yahoo.com/search?p={0}" };
new SearchEngine(){ Name = "Bing", URLPattern = "http://www.bing.com/search?q={0}" };
}
but in your code you should have only one SearchEngine object:
SearchEngine defaultSearchEngine;
so when the user enters text and chooses "Go" you check if the entered text is a valid URL (maybe using a regular expression), and if not you do this:
String url = String.Format(defaultSearchEngine.URLPattern, SearchTextBox.Text);

C# webservice losing data on return

I am programming a client program that calls a webmethod but when I get the return data there are missing values on some of the fields and objects.
The webmethod in turn is calling a WCF method and in the WCF method the return data is fine. But when it is passing to the webservice the return data is missing.
Is there any way to fix this problem?
This is my client code calling the webservice:
ReLocationDoc query = new ReLocationDoc();
query.PerformerSiteId = 1;
query.PerformerUserId = 1;
query.FromStatus = 10;
query.ToStatus = 200;
ReLocationDoc doc = new ReLocationDoc();
ServiceReference1.QPSoapClient service = new QPSoapClient();
try {
service.GetRelocationAssignment(query, out doc);
string test = doc.Assignment.Id.ToString();
} catch(Exception ex) {
MessageBox.Show(ex.Message);
}
The webmethod code is here:
[WebMethod]
return m_reLocationClient.GetRelocationAssignment(query, out reLocationDoc);
}
And at last the WCF code:
public ReLocationResult GetRelocationAssignment(ReLocationDoc query, out ReLocationDoc reLocationDoc) {
try {
LOGGER.Trace("Enter GetRelocationAssignment().");
ReLocationResult result = reLocationCompactServiceClient.GetRelocationAssignment(out reLocationDoc, query);
if(reLocationDoc.Assignment == null || reLocationDoc.Assignment.CurrentStatus == STATUS_FINISHED) {
ReLocationDoc newQuery = new ReLocationDoc();
newQuery.Assignment = new AssignmentDoc();
newQuery.Assignment.EAN = DateTime.Today.ToString();
newQuery.PerformerSiteId = QPSITE;
newQuery.PerformerUserId = QPUSER;
reLocationDoc.AssignmentStatus = m_settings.ReadyStatus; ;
result = reLocationCompactServiceClient.CreateReLocationAssignment(out reLocationDoc, newQuery);
}
return result;
} finally {
LOGGER.Trace("Exit GetRelocationAssignment().");
}
}
The GetRelocationAssignment:
public ReLocationResult GetRelocationAssignment(ReLocationDoc query, out ReLocationDoc reLocationDoc) {
try {
LOGGER.Trace("Enter GetRelocationAssignment().");
ReLocationDoc doc = new ReLocationDoc();
ReLocationResult result = new ReLocationResult();
new Database(Connection).Execute(delegate(DBDataContext db) {
User user = GetVerifiedUser(db, query, MODULE_ID);
SiteModule siteModule = SiteModule.Get(db, query.PerformerSiteId, MODULE_ID);
Status status = Status.Get(db, query.FromStatus, query.ToStatus, 0);
Status startStatus = Status.Get(db, query.FromStatus, 0);
Status endStatus = Status.Get(db, query.ToStatus, 0);
IQueryable<Assignment> assignments = Assignment.GetAssignmentsWithEndStatus(db, siteModule, endStatus);
assignments = Assignment.FilterAssignmentStartStatus(assignments, startStatus);
foreach(Assignment assignment in assignments) {
LOGGER.Debug("Handling assignment: " + assignment.Id);
result.Status = true;
AssignmentDoc assignmentDoc = FillAssignmentDoc(assignment);
//ReLocationDoc doc = new ReLocationDoc();
AssignmentStatus sts = assignment.AssignmentStatus.OrderByDescending(ass => ass.Id).First();
assignmentDoc.CurrentStatus = sts.Status.Zone;
Status currentStatus = sts.Status;
IList<Item> items = assignment.Items.ToList();
IList<ItemDoc> itemDocs = new List<ItemDoc>();
foreach(Item item in items) {
ItemDoc itemDoc = FillItemDoc(item);
ItemDetail itemDetail;
if(ItemDetail.TryGet(db, item.Id, out itemDetail)) {
ItemDetailDoc itemDetailDoc = FillItemDetailDoc(itemDetail);
itemDoc.Details = new ItemDetailDoc[1];
Event eEvent = null;
if(Event.GetEvent(db, itemDetail, currentStatus, out eEvent)) {
EventDoc eventDoc = FillEventDoc(eEvent);
itemDetailDoc.Events = new EventDoc[1];
if(eEvent.LocationId.HasValue) {
Location location = null;
if(Location.TryGet(db, eEvent.LocationId.Value, out location)) {
eventDoc.Location = new LocationDoc();
eventDoc.Location = FillLocationDoc(location, db);
}
}
itemDetailDoc.Events[0] = eventDoc;
}
itemDoc.Details[0] = itemDetailDoc;
}
itemDocs.Add(itemDoc);
}
assignmentDoc.Items = itemDocs.ToArray();
doc.Assignment = assignmentDoc;
}
}, delegate(Exception e) {
result.Message = e.Message;
});
reLocationDoc = doc;
return result;
} finally {
LOGGER.Trace("Exit GetRelocationAssignment().");
}
}
In all this code the return data is fine. It is loosing data only when passing to the webmetod.
Enter code here.
Also, the ordering of the XML tags in the message makes difference - I had a similar problem about maybe two years ago, and in that case parameter values were dissappearing during transmission because the sending part ordered the tags differently than what was defined in the schema.
Make surethe XML tags are being accessed with the same casing at either end. if the casing is not the same then the value won't be read.
You should check it all message are sending back from your webservice. Call your webservice manually and check its response.
If all data is there, probably your webservice reference is outdated; update it by right-clicking your webservice reference and choose "Update"
If your data don't came back, your problem is probably related to webservice code. You should check your serialization code (if any) again, and make sure all returned types are [Serializable]. You should check if all return types are public as it's mandatory for serialization.
As noted per John Saunders, [Serializable] isn't used by XmlSerializer.

Categories