I am trying to use appwrite server sdk list users to get userid from an email.
The documentation says there is a search: option that can be used but no where does it say what the format of that String? is.
What is the format of the search: String? to only get a list of users whose email matches?
void main() { // Init SDK
Client client = Client();
Users users = Users(client);
client
.setEndpoint(endPoint) // Your API Endpoint
.setProject(projectID) // Your project ID
.setKey(apiKey) // Your secret API key
;
Future result = users.list(search: '<<<WHAT GOES HERE>>>');
}
:wave: Hello!
Thanks for bringing this question up, this is definitely not well documented, I'll note this down and try to make it clearer in the docs, but here's how you'd approach this in Dart:
final res = users.list(search: Query.equal('email',
'email#example.com'));
res.then((response) {
print(response.users[0].toMap());
}).catchError((error) {
print(error);
});
The Query object generates a query string, and works similar to how listDocument would work. The difference here is that it only takes a single query string instead of a list.
I am using Unity 5.5.2f1 pro and facebook's SDK v 7.9.4
I have a script which after login (managed in a previous scene) sends an API request to FB asking for friends, name and email and sends that info as a POST to a php website.
code:
[Serializable]
public struct FBData {
public string first_name;
public string email;
public string friends;
public string id;}
public class UserManagement : MonoBehaviour {
string urlSaveUserData="some php website";
public Text testTxt;
FBData parsedData;
// Use this for initialization
void Start () {
//Check if it's the first time the user is opening the app.
if (UserInfo.FIRST_TIME) {
//update text (only used for testing, should be removed in production.)
testTxt.text = "Your user id is: " + UserInfo.ID;
//Perform FB.API call to get User Data.
getUserData ();
//Save in SQL table. (won't get here if line in getUserData() is active)
StartCoroutine ("saveUserData");
} else {
//do something else.
}
note: Since this is meant for iOS I have to test it on a device so I'm using text in the screen to display info (think of it as a badly implemented print statement).
The problem: In my callback function for FB.API I write in the text Gameobject (aka testTxt) the parsed information from the response which is saved in the Custom UserInfo clss. It display's correctly but the code gets stuck there. It doesn't continue to the next function. HOWEVER, if I delete/comment that line and don't display anything in the text field. The codes does continue to the POST function BUT the information from the API call is not passed, i.e my custom class is empty (leading me to believe the callback function is not called at all).
public void getUserData(){
string query = "me?fields=first_name,email,friends";
FB.API (query, HttpMethod.GET, Apicallback, new Dictionary<string, string> ());
}
private void Apicallback(IGraphResult result){
//Parse Graph response into a specific class created for this result.
parsedData = JsonUtility.FromJson<FBData>(result.RawResult);
//Pass each field into UserInfo class.
UserInfo.EMAIL = parsedData.email;
UserInfo.FRIENDS = parsedData.friends;
UserInfo.NAME = parsedData.first_name;
UserInfo.FACEBOOKID = parsedData.id;
/*problem area, if I comment line below, then previous information is apparently not stored. If left as is then testTxt displays correct information but code gets stuck there. */
testTxt.text = "This is the info from USerInfoInside the APICallback: " + UserInfo.EMAIL + UserInfo.FRIENDS + UserInfo.FACEBOOKID;
}
The function below is to send info to php website, is there for illustrative purposes:
code:
public IEnumerator saveUserData() {
//get user info (this information is EMPTY if line in getUserData() is commented.
parsedData.id = UserInfo.FACEBOOKID;
parsedData.friends = UserInfo.FRIENDS;
parsedData.first_name = UserInfo.NAME;
parsedData.email = UserInfo.EMAIL;
//translate data into json
string JsonBodyData = JsonUtility.ToJson (parsedData);
//Custom web request (POST method doesnt seem to work very well, documentation example sends empty form)
var w = new UnityWebRequest(urlSaveUserData, "POST");
byte[] bodyRaw = new System.Text.UTF8Encoding().GetBytes(JsonBodyData);
w.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw);
w.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
w.SetRequestHeader("Content-Type", "application/json");
yield return w.Send();
//work with received data...}
Im stuck here any help is appreciated. Thanks!
Be sure to use EscapeURL when using strings directly for JSON or HTTP POST and GET methods. The lack of this treatment tends to screw things over, particulary in iOS platforms.
From what I can see, this code
string query = "me?fields=first_name,email,friends";
should instead be escaped as
string query = WWW.EscapeURL("me?fields=first_name,email,friends");
so characters like "?" won't get encoded as an URL symbol.
I'm assuming you don't need to do that for your illustrative example, because UnityWebRequest already escapes your POST request strings internally, but I can't fully confirm that.
This is regarding Sendgrid incoming mail webhook, I have referred this URL SendGrid incoming mail webhook - how do I secure my endpoint, and got some idea how to go about this, but, as I am new to MVC / WebAPI, could anyone give me the controller method code snippet to catch the JSON format HTTP post and save to my application folder.
This is the solution I found after googling and with slight modifications:
[HttpPost, HttpGet]
[EnableCors(origins: "*", headers: "*", methods: "*")]
public async Task Post()
{
if (Request.Content.IsMimeMultipartContent("form-data"))
try
{
//To get complete post in a string use the below line, not used here
string strCompletePost = await Request.Content.ReadAsStringAsync();
HttpContext context = HttpContext.Current;
string strFrom = context.Request.Form.GetValues("from")[0];
string strEmailText = context.Request.Form.GetValues("email")[0];
string strSubject = context.Request.Form.GetValues("subject")[0];
//Not useful I guess, because it always return sendgrid IP
string strSenderIP = context.Request.Form.GetValues("sender_ip")[0];
}
catch (Exception ex)
{
}
}
I tried, retrieving the values as
String to = context.Request.Params["to"];
but, the value returned is not consistent, i.e. most of the times it is returning null and occasionally returns actual value stored in it.
If anyone have a better solution, please let me know.
Thank you
If for some reason ["to"] doesn't work for you, try to get ["envelope"] value,
context.Request.Form.GetValues("envelope")[0]
which looks like
{"to":["emailto#example.com"],"from":"emailfrom#example.com"}
I'm trying to post a message on the timeline in the past and I get the following error:
"Facebook.FacebookOAuthException : (OAuthException - #100) (#100) You cannot specify a scheduled publish time on a published post"
I tried to put the current date, a past date or a future date; the result is the same.
I think it may be a problem with the way I obtain the unix timestamp.
Here is the code:
public void PostPostsOnTestUserTimeline()
{
string userId = "[TEST_USER_ID]";
var client = new FacebookClient(accessToken);
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article - 39";
parameters.scheduled_publish_time = GetUnixTimestamp(DateTime.Now.AddMinutes(20));
client.Post(string.Format("{0}/feed", userId), parameters);
}
private long GetUnixTimestamp(DateTime dateTime)
{
double secondsDouble = (dateTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds;
return Convert.ToInt64(secondsDouble);
}
Any idea why it crashes?
I am writing on the timeline of a test user created at "created_time": "2013-03-05T12:34:15+0000". If I don't specify the scheduled_publish_time, it works fine.
Thank you,
Iulia
There's no way to backdate feed posts on user timelines - this feature only exists for Pages or for Open Graph publishing
I have a app of google app engine for for java and it have a facebook form which on submitting send a signed_request to a servlet in our app. We are using following code to unencrypt and convert to a json string
String signedRequest = (String) req.getParameter("signed_request");
String payload = signedRequest.split("[.]", 2)[1];
payload = payload.replace("-", "+").replace("_", "/").trim();
String jsonString = new String(Base64.decodeBase64(payload.getBytes()));
System.out.println("Json is::" + jsonString);
The response looks like
[sakshumweb/3.361739372881481188].: Json is::{"algorithm":"HMAC-SHA256","expires":1347588000,"issued_at":1347584290,"oauth_token":"XXXXX","registration":{"name":"Vik Kumar","first_name":"Vik","last_name":"Kumar","bloodGroup":"B-","gender":"male","birthday":"10/31/1983","email":"vik.ceo\u0040gmail.com","cellPhone":"1234123456","homePhone":"1234123457","officePhone":"1234123458","primaryAddress":"jdfjfgj","area":"jfdjdfj","location":{"name":"Redwood Shores, California","id":103107903062719},"subscribe":true,"eyePledge":false,"reference":"fgfgfgfg"},
"registration_metadata":{"fields":"[{\"name\":\"name\"},{\"name\":\"first_name\"},{\"name\":\"last_name\"}, {\"name\":\"bloodGroup\", \"description\":\"Blood Group\", \"type\":\"select\", \"options\":{\"A+\":\"A+\",\"A-\":\"A-\",\"B+\":\"B+\",\"B-\":\"B-\",\"O+\":\"O+\",\"O-\":\"O-\",\"AB+\":\"AB+\",\"AB-\":\"AB-\",\"A1+\":\"A1+\",\"A1-\":\"A1-\",\"A2+\":\"A2+\",\"A2-\":\"A2-\",\"A1B+\":\"A1B+\",\"A1B-\":\"A1B-\",\"A2B+\":\"A2B+\",\"A2B-\":\"A2B-\",\"HH\":\"Bombay Blood Group\"}}, {\"name\":\"gender\"}, {\"name\":\"birthday\"},{\"name\":\"email\"}, {\"name\":\"cellPhone\", \"description\":\"Cell Number\", \"type\":\"text\"}, {\"name\":\"homePhone\", \"description\":\"Home Number\", \"type\":\"text\"}, {\"name\":\"officePhone\", \"description\":\"Office Number\", \"type\":\"text\"}, {\"name\":\"primaryAddress\", \"description\":\"Primary Address\", \"type\":\"text\"}, {\"name\":\"area\", \"description\":\"Locality/Village/Area\", \"type\":\"text\"},{\"name\":\"location\"}, {\"name\":\"subscribe\", \"description\":\"Subscribe me for the Sakshum activites updates.\", \"type\":\"checkbox\", \"default\":\"checked\"}, {\"name\":\"eyePledge\", \"description\":\"I want to pledge my eyes as well.\", \"type\":\"checkbox\"}, {\"name\":\"reference\", \"description\":\"How you reached to us (Friend, Facebook, google etc.)?\", \"type\":\"text\"}]"},"user":{"country":"us","locale":"en_GB"},"user_id":"875390603"}
So, how do i parse this data to extract the data in registration part of this response?
Since this is a valid JSON, you can use JSON library like Jackson or GSON to parse it.
You can use this example code to print out all registration fields:
JsonNode json = new ObjectMapper().readTree(response);
JsonNode registration_fields = json.get("registration");
Iterator<String> fieldNames = registration_fields.getFieldNames();
while(fieldNames.hasNext()){
String fieldName = fieldNames.next();
String fieldValue = registration_fields.get(fieldName).asText();
System.out.println(fieldName+" : "+fieldValue);
}