Limit the fields return by twitter api Json format - json

I have read the documentation provided by the twitter, but it seem I haven't found how to limit the fields returned in my script.
here's my script
$url = 'http://api.twitter.com/1/statuses/home_timeline.json';
$params['count'] = 1;
$params['oauth_version'] = '1.0';
$params['oauth_nonce'] = mt_rand();
$params['oauth_timestamp'] = time();
$params['oauth_consumer_key'] = $consumer_key;
$params['oauth_token'] = $access_token;
what params should I add?

There are few, if any, field (de)selectors for the Twitter API. Some timeline and tweet delivery methods support trim_user=true as a parameter to remove the fully embedded user objects but that's pretty much the only way to obtain less data per individual tweet object.

Related

Limit questions

I'm make quiz app on flutter and have local json with
questions(around 200). How i can limit questions for 40?
because when i open app its show me all question
json={results:[
{question},
]}
final jsonResponse = convert.jsonDecode(json);
final result = (jsonResponse['results'] as List).map((question)
=> QuestionModel.fromJson(question));
questions.value =
result.map((question) =>
Question.fromQuestionModel(question)).toList();
return true;
}
}
Use subList function after using .toList().
this can be done easily by using .subList() which basically returns a list from the start index to the end index parameters from your original List ,like this
final result = (jsonResponse['results'] as List).map((question)
=> QuestionModel.fromJson(question));
questions.value =
result.map((question) =>
Question.fromQuestionModel(question)).toList().sublist(0,39);
Note
if you want to save all the 200 Questions and get every 40 questions then you should use pagination ,in this case you'll not use the subList function here, you'll use it after returning the result with the list that should be attached with the ui part.
Bonus Tip
check out this flutter plugin flutter page wise which makes the pagination alot easier, it can very helpful in a lot of situations.

Returning all items /whats-new API call

We are using self-hosted ActiveCollab v5.13.60 and I'm trying to generate a list of completed projects and tasks given a specific date. I've been toying with /whats-new/daily/ API request since it also gives a related object so I can pull in the project/task name easily.
From what I can tell the request only returns the last 50 items, if there are more than 50 items, then additional requests can be made with a ?page=X parameter.
Is there a way this request can return an un-paginated list, or all items for a given day?
Thanks!
Unfortunately not, you have to keep requesting the next page until there is nothing returned and then combine all of the results.
Within our in-house application, we have the following function (in PHP)
/**
* Get pages of data with passed url
* #param [string] $url The api endpoint
* #return [array] All your data
*/
function getPagedData($url) {
// Get all the projects in active collab
$page = 1;
$paged_records = array();
$paged_records_results = $this->activeCollabClient->get($url . '?page=' . $page)->getJson();
$paged_records = array_merge($paged_records, $paged_records_results);
// Loop through pages
while ($paged_records_results = $this->activeCollabClient->get($url . '?page=' . ++$page)->getJson()) {
$paged_records = array_merge($paged_records, $paged_records_results);
}
return $paged_records;
}
It can then be called, passing the URL. In your case it could be used like:
getPagedData('whats-news/daily');
You will then get an array returned with all of the information contained.

NamedList with Deep Pagination

QueryRequest req=new QueryRequest(solrQuery);
NoOpResponseParser responseParser = new NoOpResponseParser();
responseParser.setWriterType("csv");
searcherServer.setParser(responseParser);
NamedList<Object> resp=searcherServer.request(req);
QueryResponse res = searcherServer.query(solrQuery);
responseString = (String)resp.get("response");
I use the above code to get the output in CSV format. The data I am trying to fetch is huge (In billions). So I want to include deep pagination of SOLR and get chunks of CSV output. Is there a way to do? Also, with the current version of SOLR (I cannot upgrade) I have to use the above code to get CSV output.
I tried the below way to fetch the results.
searcherServer = new HttpSolrServer(url);
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery(query);
solrQuery.set("fl","field1");
solrQuery.setParam("wt", "csv");
solrQuery.setStart(0);
solrQuery.setRows(1000);
solrQuery.setSort(SolrQuery.SortClause.asc("field2"));
In the output from the above code has wt as javabin. So I cannot get the CSV output.
Any suggestions?
You have two ways.
use Solr export request handler (or add it) and wt=csv parameter. Just to be clear, this is an Implicit Request Handler usually available even in older Solr versions and specifically designed to handle scenarios that involve exporting millions of records.
implement deep paging correctly. I suggest Yonic post paging and deep paging, it easier than you think. But after you'll have correctly implement, you also need to create the csv file by yourself.
The solution I found was:
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery(query); //what you want to fetch
QueryResponse res = searcherServer.query(solrQuery);
int numFound = (int)res.getResults().getNumFound();
int rowsToBeFetched = (numFound > 1000 ? (int)(numFound/6) : numFound);
for(int i=0; i< numFound; i=i+rowsToBeFetched ){
solrQuery.set("fl","fieldToBeFetched");
solrQuery.setParam("wt", "csv");
solrQuery.setStart(i);
solrQuery.setRows(rowsToBeFetched);
QueryRequest req=new QueryRequest(solrQuery);
NoOpResponseParser responseParser = new NoOpResponseParser();
responseParser.setWriterType("csv");
searcherServer.setParser(responseParser);
NamedList<Object> resp=searcherServer.request(req);
responseString = (String)resp.get("response"); //This is in CSV format
}
Pros:
Since I don't get the result at once, it was faster.
The output was csv.
Hitting solr multiple items isn't costly.
Cons:
The result is not unique, meaning there can be repeated data based on what you are fetching.
To get unique results, you can use facets.
Thanks!

Username in WebTokenRequestResult is empty

in a Windows 10 UWP I try use WebAuthenticationCoreManager.RequestTokenAsync to get the result from a login with a Microsoft account.
I get a WebTokenRequestResult with Success. ResponseData[0] contains a WebAccount with an ID - but the UserName is empty.
The scope of the call is wl.basic - so I should get a lot of information...
I'm not sure how to retrieve extra information - and for the current test the Username would be OK.
I checked out the universal samples - and there I found a snippet which tries to do what I'm trying - an output of webTokenRequestResult.ResponseData[0].WebAccount.UserName.
By the way - the example output is also empty.
Is this a bug - or what do I (and the MS in the samples) have to do to get the users profile data (or at least the Username)?
According to the documentation (https://learn.microsoft.com/en-us/windows/uwp/security/web-account-manager), you have to make a specific REST API call to retrieve it:
var restApi = new Uri(#"https://apis.live.net/v5.0/me?access_token=" + result.ResponseData[0].Token);
using (var client = new HttpClient())
{
var infoResult = await client.GetAsync(restApi);
string content = await infoResult.Content.ReadAsStringAsync();
var jsonObject = JsonObject.Parse(content);
string id = jsonObject["id"].GetString();
string name = jsonObject["name"].GetString();
}
As to why the WebAccount property doesn't get set... shrugs
And FYI, the "id" returned here is entirely different from the WebAccount.Id property returned with the authentication request.

JSON validator validates the JSON but my left hand tags are not appearing

i am developing an iOS app and this app fetches data using JSON from mysql database. i have configured the json properly so far. right hand $outputs are ok and json validator validated the json formatting is completely ok. but my left hand tags are not appearing some how. here i m providing the code what i did. For this app publishing is on hold for long time.
//fetch data from current month table
$q = mysql_query("SELECT * FROM $monthyear where news_date = '$date'");
if (!$q) {
die('Invalid query executed: ' . mysql_error());
}
while($e=mysql_fetch_row($q)){
$output[]=$e;
$responce[$e]['news_id'] = $output['news_id'];
$responce[$e]['news_title'] = $output['news_title'];
$responce[$e]['news_reporter'] = $output['news_reporter'];
$responce[$e]['news_details'] = $output['news_details'];
$responce[$e]['photo'] = $output['photo'];
$responce[$e]['path'] = 'admin/'.str_replace('\\','',$output['path']);
$responce[$e]['menu_id'] = $output['menu_id'];
$responce[$e]['menu_type'] = $output['menu_type'];
$responce[$e]['news_publish_status'] = $output['news_publish_status'];
$responce[$e]['news_order'] = $output['news_order'];
$responce[$e]['news_date'] = $output['news_date'];
$responce[$e]['news_time'] = $output['news_time'];
$responce[$e]['added_by'] = $output['added_by'];
$responce[$e]['directory'] = $output['directory'];
$responce[$e]['read_number'] = $output['read_number'];
$responce[$e]['comment_number'] = $output['comment_number'];
$responce[$e]['news_comment_table_name'] = $output['news_comment_table_name'];
}
echo(json_encode($output));
I am not getting any way to show left hand tags though it exists in the script. can any one help me on this by guiding or giving an example from existing source code after modifications. TIA
Ishtiaque
You are using $e which is an array as an array key in $response[$e], and this is not allowed in PHP:
Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type.
I think you want to use the ID as a key.