So basically I have a QR code generator in the app, I already implemented a feature generating it with url, such as domain.com/userid?=111.
So, now I want QR code scanner to scan it and get only the id part of the user out of it, like it scanned the url example provided above, and then I just want to get '111' part to process.
How can I implement it?
Use Uri queryParametersAll:
Uri url = Uri.parse('https://www.example.com/?userid=111');
print(url.queryParametersAll['userid'][0]);
You can use substring method to get the part of it.
// Dart 2.6.1
main() {
String str = "domain.com/userid?=111";
print(str.substring(str.indexOf("=")+1));
}
Related
Is anyone knows how Flutter URI encoding/decoding works?
I have one issue. Let me give you some background on the issue. We have one deep link which will give us the email and access token code to reset the password. We will validate the token on the front end and then allow users to do a reset.
Here is the sample URL from Firebase dynamic link
https://example.com/auth/resetPassword/?access_token=abcd&email=test+abc#xyz.com
Firebase dynamic link will give us this URL in the URI object. The issue is when I try to fetch the query params from this URI object, it removes plus sign from an email and replaces it with the space character instead. E-mail should same as displayed in the above link. This is the email received when I fetch query params: test abc#xyz.com
I have created two dart pads to figure out the issue. Here is the 1st sample where I am parsing (since firebase dynamic link is doing the same) the URL into the URI object and tried printing the output. As expected it removes the plus sign.
Code:
main() {
var httpsUri = Uri.parse("https://example.com/auth/resetPassword/?access_token=abcd&email=test+abc#xyz.com");
print(httpsUri.queryParameters);
}
Output:
{access_token: abcd, email: test abc#xyz.com}
In another sample, I tried creating the URI object from the same parameters and link but manually. Here is the code
Code:
main() {
var httpsUri = Uri(
scheme: 'https',
host: 'example.com',
path: '/auth/resetPassword/',
queryParameters: {
'access_token': 'abcd',
'email': 'test+abc#xyz.com'
});
print(httpsUri.queryParameters);
}
Output:
{access_token: abcd, email: test+abc#xyz.com}
If you see here, the email is correctly displayed.
My exact scenario is matching with the first sample code. Based on my findings it removes the plus sign due to encoding and decoding of the URL as a plus sign has a special meaning in the URL. But on the other hand why it is not happening in 2nd example?
Any help would be appreciated!
+ is a reserved character for URIs and therefore should be encoded to %2B if you want a literal + character.
But on the other hand why it is not happening in 2nd example?
Your second example works because it constructs a Uri object directly, and if you were to convert it to a String, it would perform necessary encodings for you. That is, print(httpsUri) would output:
https://example.com/auth/resetPassword/?access_token=abcd&email=test%2Babc%40xyz.com
rather than original (malformed) URL:
https://example.com/auth/resetPassword/?access_token=abcd&email=test+abc#xyz.com
I simply request(to elasticsearch) in browser fine:
in .Net, I want to post same request and expected to get json data seem in pic above, but here is the exception.:
What is the point of this failure?
Why are you calling UploadString()? Simply invoke DownloadString() for the entire URL and you'll be good to go:
var data = webc.DownloadString("http://localhost/.../ability");
Please use DownloadString method instead of UploadString:
var asd = webc.DownloadString("http://localhost:9200/dota2/_mapping/agust/field/ability");
Is there a way to retrieve language-specific name for a user, using Graph API?
I am finding answer of this question. And finally, I got a solution for this.
step 1. First, request below api
/v2.4/me?fields=id,name,locale
then, you received locale information of the user.
step 2. Now, request below api
/v2.4/me?fields=id,name?locale="locale received in step 1"
If you use android facebook sdk like me, then write code like below.
Bundle bundle = new Bundle();
bundle.putString("fields", "id,name,locale");
//bundle.putString("locale", "ko_KR");
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me",
bundle,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.d(TAG, "response -> " + response.getRawResponse());
}
}
).executeAsync();
"me" can be converted into "". I tested in the graph api(v2.4). Thank you!
Not sure if that’s what you mean, but there’s a field called "name_format" in the FQL user table:
name_format : string : The user's name formatted to correctly handle Chinese, Japanese, Korean ordering.
Edit: No, sorry, I’m just realizing this only gives you something like "name_format": "{first} {last}", so that first and last name can be printed out in the right order.
I am trying to use HTTP to POST a file to an outside API from within a grails service. I've installed the rest plugin and I'm using code like the following:
def theFile = new File("/tmp/blah.txt")
def postBody = [myFile: theFile, foo:'bar']
withHttp(uri: "http://picard:8080/breeze/project/acceptFile") {
def html = post(body: postBody, requestContentType: URLENC)
}
The post works, however, the 'myFile' param appears to be a string rather than an actual file. I have not had any success trying to google for things like "how to post a file in grails" since most of the results end up dealing with handling an uploaded file from a form.
I think I'm using the right requestContentType, but I might have missed something in the documentation.
POSTing a file is not as simple as what you have included in your question (sadly). Also, it depends on what the API you are calling is expecting, e.g. some API expect files as base64 encoded text, while others accept them as mime-multipart.
Since you are using the rest plugin, as far as I can recall it uses the Apache HttpClient, I think this link should provide enough info to get you started (assuming you are dealing with mime-multipart). It shouldn't be too hard to change it around to work with your API and perhaps make it a bit 'groovy-ier'
If some one come to my url suppose /get it should give back a xml/application format in response in bottle framework. How can i do this? i am using elementree as xml generator.
Look on the official page for the cookie example and do it like this:
#route('/xml')
def xml():
response.headers['Content-Type'] = 'xml/application'
....(create the xml here)......
return xml_content_whatever