React Native: Display JSON data in Flatlist - react-native-flatlist

I am trying to get only "name" from below JSON response but it's not getting.Please help me...
JSON Response
data = "Data": {
"0": {
"Restaurant": {
"id": "1",
"name": "Restaurant 1"
}
},
"1": {
"Restaurant": {
"id": "2",
"name": "Restaurant 2"
}
}
}
React Native Flatlist Code
<FlatList
data={this.state.data}
renderItem={({item}) =>
<View style={styles.container}>
<Text style={styles.restaurant_name}>{item.Restaurant.name}</Text>
</View>
}
/>

Related

A secondary window unexpectedly pops up on clicking notification (via OneSignal) in iOS

Does anyone here have experience integrating push notifications on iOS on OneSignal with mobile apps built using Expo?
I have an app which opens a WebView and this WebView handles all the navigation (i.e. no app routes, instead web routes). The issue is that upon clicking a notification from OneSignal containing a launchURL (a web URL which is supposed to open in the WebView inside the app which I have handled programmatically), a bottom sheet (with a button "Done" on top-right) opens up instead.
You can view the video of the issue here.
My app.json:
{
"expo": {
"name": "Engage | Dev",
"scheme": "fudrengage",
"slug": "fudr-engage-app",
"version": "1.0.14",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "https://assets.fudr.in/assets/images/splash.png",
"resizeMode": "cover",
"backgroundColor": "#EB9658"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "in.fudr.devengage",
"associatedDomains": ["applinks:devengage.fudr.in"]
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
},
"package": "in.fudr.devengage",
"intentFilters": [
{
"action": "VIEW",
"autoVerify": true,
"data": [
{
"scheme": "https",
"host": "devengage.fudr.in",
"pathPrefix": "/*"
}
],
"category": [
"BROWSABLE",
"DEFAULT"
]
}
]
},
"web": {
"favicon": "./assets/favicon.png"
},
"plugins": [
[
"onesignal-expo-plugin",
{
"mode": "development",
"devTeam": "XXXXXX"
}
],
["./plugins/withAndroidVerifiedLinksWorkaround"]
],
"notification": {
"icon": "./assets/notification-icon.png",
"color": "#EB9658",
"androidMode": "default",
"androidCollapsedTitle": "Updates from Fudr",
"iosDisplayInForeground": true
},
"extra": {
"eas": {
"build": {
"experimental": {
"ios": {
"appExtensions": [
{
"targetName": "OneSignalNotificationServiceExtension",
"bundleIdentifier": "in.fudr.devengage.OneSignalNotificationServiceExtension",
"entitlements": {
"com.apple.security.application-groups": [
"group.in.fudr.devengage.onesignal"
]
}
}
]
}
}
},
"projectId": "xxxxxx"
}
}
}
}
Testing environment:
"react-native-onesignal": "4.4.1"
"onesignal-expo-plugin": "1.1.1"
"expo": "46.0.7"
iOS 16
"react-native": "0.69.5"
As per the OneSignal docs here, the launchURLs that trigger the browser in iOS as well as Android, can be suppressed by adding "OneSignal_suppress_launch_urls": true in the infoPlist key the ios section config in app.json
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.example.sub",
"associatedDomains": ["applinks:sub.example.com"],
"infoPlist": {
"OneSignal_suppress_launch_urls": true
}
},
My App.js was already handling launchURLs inside the WebView as shown below:
export default App = () => {
OneSignal.setAppId("xxxxxx");
const webviewRef = useRef(null);
const [webviewSourceURL, setWebviewSourceURL] = useState("");
useEffect(() => {
// Method for handling notifications opened
OneSignal.setNotificationOpenedHandler((notification) => {
const notificationId = notification?.notification?.notificationId ?? "";
const notificationLaunchUrl = notification?.notification?.launchURL;
const launchURL =
notificationId && notificationLaunchUrl
? `${notificationLaunchUrl}?notificationId=${notificationId}` // Append notificationId as a query parameter to generate a unique URL everytime a new notification is opened; this helps WebView know that it's a new visit
: "";
if (notificationId && launchURL) {
setWebviewSourceURL(launchURL);
}
});
}, []);
return() {
<WebView
ref={webviewRef}
originWhitelist={["*"]}
source={{
uri: webviewSourceURL || FALLBACK_URL,
}}
style={{ marginTop: 20, marginBottom: 5 }}
startInLoadingState={true}
renderLoading={LoadingIndicatorView}
onMessage={onMessage}
/>
}
}

Google ads rest api cannot create a campaign "MUTATE_ACTION_NOT_PERMITTED_FOR_CLIENT"

I'm trying to create Google Ads campaigns using the Google Adwords API and getting this error MUTATE_ACTION_NOT_PERMITTED_FOR_CLIENT
I'm calling this endpoint:
https://googleads.googleapis.com/v10/customers/customerID/campaigns:mutate
with the payload:
{
"operations": [
{
"create": {
"status": "PAUSED",
"advertisingChannelType": "SEARCH",
"advertisingChannelSubType": "SEARCH_EXPRESS",
"paymentMode": "CONVERSIONS",
"name": "TestCampaign",
"campaignBudget": "customers/${customerID}/campaignBudgets/${budgetId}",
"biddingStrategyType": "COMMISSION",
}
}
]
}
Here is the response:
"errors": [
{
"errorCode": {
"operationAccessDeniedError": "MUTATE_ACTION_NOT_PERMITTED_FOR_CLIENT"
},
"message": "A mutate action is not allowed on this resource, from this client.",
"trigger": {
"stringValue": ""
},
"location": {
"fieldPathElements": [
{
"fieldName": "operations",
"index": 0
},
{
"fieldName": "create"
},
{
"fieldName": "advertising_channel_sub_type"
}
]
}
},
{
"errorCode": {
"operationAccessDeniedError": "OPERATION_NOT_PERMITTED_FOR_CAMPAIGN_TYPE"
},
"message": "This operation is not permitted on this campaign type",
"trigger": {
"stringValue": "SEARCH(SEARCH_EXPRESS)"
},
"location": {
"fieldPathElements": [
{
"fieldName": "operations",
"index": 0
},
{
"fieldName": "create"
},
{
"fieldName": "payment_mode"
}
]
}
}
],

"Invalid JSON payload received." when creating a new sheet

I'm just starting out with the Sheets API, and I'm following this setup to create a new sheet: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/create
In this code, the spreadsheetBody object is empty. For this I've used the example on this page: https://developers.google.com/sheets/api/samples/writing and added this code to the spreadsheetBody variable:
{
"range": "Sheet1!A1:D5",
"majorDimension": "ROWS",
"values": [
["Item", "Cost", "Stocked", "Ship Date"],
["Wheel", "$20.50", "4", "3/1/2016"],
["Door", "$15", "2", "3/15/2016"],
["Engine", "$100", "1", "30/20/2016"],
["Totals", "=SUM(B2:B4)", "=SUM(C2:C4)", "=MAX(D2:D4)"]
],
}
However, when I post this I get the error "Invalid JSON payload received. Unknown name "range" at 'spreadsheet': Cannot find field.". What might be wrong here?
The request body you are using is for spreadsheets.values.update.
As a sample, the request body for creating Spreadsheet is as follows. In this sample request body, ["Item", "Cost", "Stocked", "Ship Date"], ["Wheel", "$20.50", "4", "3/1/2016"] was used from the document you use.
Sample request body:
{
"properties":
{
"title": "sampleSpreadsheet"
},
"sheets":
[
{
"data":
[
{
"startRow": 0,
"startColumn": 0,
"rowData":
[
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "Item"
}
},
{
"userEnteredValue":
{
"stringValue": "Cost"
}
},
{
"userEnteredValue":
{
"stringValue": "Stocked"
}
},
{
"userEnteredValue":
{
"stringValue": "Ship Date"
}
}
]
},
{
"values":
[
{
"userEnteredValue":
{
"stringValue": "Wheel"
}
},
{
"userEnteredValue":
{
"numberValue": 20.5
},
"userEnteredFormat":
{
"numberFormat":
{
"type": "NUMBER",
"pattern": "$##.00"
}
}
},
{
"userEnteredValue":
{
"numberValue": 4
}
},
{
"userEnteredValue":
{
"numberValue": 42372
},
"userEnteredFormat":
{
"numberFormat":
{
"type": "DATE",
"pattern": "d/m/yyyy"
}
}
}
]
}
]
}
]
}
]
}
Note:
When this request body is used for spreadsheets.create, a Spreadsheet with the filename of sampleSpreadsheet is created. The sheet has the values of ["Item", "Cost", "Stocked", "Ship Date"], ["Wheel", "$20.50", "4", "3/1/2016"] at "A1:D2".
References:
spreadsheets.create- spreadsheets.batchUpdate

TFS 2017 Work item Extension not working

New to this TS scripting so a little help is requested,
I'm trying to create an extension that created a url from 4 work item fields.
example contribution:
{
"manifestVersion": 1,
"id": "tritech-tfsurl-control",
"version": "0.1.18",
"name": "tritech-tfsurl-control",
"scopes": [ "vso.work", "vso.work_write" ],
"description": "4 fields to a url",
"publisher": "TriTech-Software-Systems",
"icons": {
"default": "img/logo.png"
},
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"tags": [
"Work Item",
"Work Item control",
"Url",
"Url tfs server"
],
"content": {
"details": {
"path": "details.md"
}
},
"links": {
"home": {
"uri": "http://www.Tritech.com"
}
},
"branding": {
"color": "rgb(220, 235, 252)",
"theme": "light"
},
"files": [
{
"path": "img",
"addressable": true
},
{
"path": "index.html",
"addressable": true
}
],
"categories": [
"Plan and track"
],
"contributions": [
{
"id": "tfsurlcontrol-action",
"type": "ms.vss-work-web.work-item-form-control",
"description": "Work Item fields to create url from",
"targets": [
"ms.vss-work-web.work-item-form"
],
"properties": {
"name": "tfsurl-control",
"uri": "index.html",
"height": 90,
"inputs": [
{
"id": "PreviousTFSServer",
"description": "The TFS server url that has the work item.",
"type": "WorkItemField",
"properties": {
"workItemFieldTypes": [ "String" ]
},
"validation": {
"dataType": "String",
"isRequired": true
}
},
{
"id": "TFSCollection",
"description": "The original tfs collection name",
"type": "WorkItemField",
"properties": {
"workItemFieldTypes": [ "String" ]
},
"validation": {
"dataType": "String",
"isRequired": true
}
},
{
"id": "TfsTeamProject",
"description": "Original TFS project name",
"type": "WorkItemField",
"properties": {
"workItemFieldTypes": [ "String" ]
},
"validation": {
"dataType": "String",
"isRequired": true
}
},
{
"id": "TfsWorkItemId",
"description": "Original work item id",
"type": "WorkItemField" ,
"properties": {
"workItemFieldTypes": [ "Integer" ]
}
}
]
}
}
]
}
then in my App.ts file is this,
///<reference types="vss-web-extension-sdk" />
import { Controller } from "./control";
import * as ExtensionContracts from "TFS/WorkItemTracking/ExtensionContracts";
import { WorkItemFormService } from "TFS/WorkItemTracking/Services";
var control: Controller;
var provider = () => {
return {
onLoaded: (workItemLoadedArgs: ExtensionContracts.IWorkItemLoadedArgs) => {
control = new Controller();
}
}
};
VSS.register(VSS.getContribution().id, provider);
this is my Control.ts file,
`
private _initialize(): void {
this._inputs = VSS.getConfiguration().witInputs;
this._ServerFieldName = this._inputs["PreviousTFSServer"];
this._CollectionFieldName = this._inputs["TFSCollection"];
this._ProjectFieldName = this._inputs["TFSTeamProject"];
this._WorkItemIdFieldName = this._inputs["TfsWorkItemId"];
WitService.WorkItemFormService.getService().then(
(service) => {
Q.spread<any, any>(
[ service.getFieldValue(this._ServerFieldName),service.getFieldValue(this._CollectionFieldName),
service.getFieldValue(this._ProjectFieldName),service.getFieldValue(this._WorkItemIdFieldName)],
(server: string, collection: string, project:string, id: number) => {
this._view = new View(server,collection,project,id);
}, this._handleError
).then(null, this._handleError);
},
this._handleError);
}
private _handleError(error: string): void {
let errorView = new ErrorView(error);
}
}
`
Then I added a view.ts
export class View {
constructor(server: string, collection: string, project: string, id: number) {
// container div
if(server)
{
var Container = $("<div />");
var workItemUrl = $("<span></span>").text("Original work item");
var a = $("<a> </a>");
var url = 'server + "/" + collection + "/" + project + "/_workitemId?=" + String(id)'
a.attr("href", url );
a.attr("target", "_blank");
a.text("here.");
workItemUrl.append(a);
//$('body').empty().append(Container);
$(".events").append(workItemUrl);
}
}
}
<Input Id="PreviousTFSServer" Value="TriTech.Source.Server" />
<Input Id="TFSCollection" Value="TriTech.Source.Collection" />
<Input Id="TFSTeamProject" Value="TriTech.Source.Project" />
<Input Id="TfsWorkItemId" Value="TriTech.Source.Id" />
</Inputs>
</ControlContribution>
</Group>`
I started with the latest edition of the vsts-extension-ts-seed-simple-master package. Compiles and creates the extension but I'm not seeing any url or link.
What am I missing?
The WIT has been edited to use the extension.
Web debug shows it is being loaded,
{"id":"TriTech-Software-Systems.tritech-tfsurl-control.tritech-tfsurlcontrol-action","description":"Work Item fields to create url from","type":"ms.vss-work-web.work-item-form-control-group","targets":["ms.vss-work-web.work-item-form"],"properties":{"name":"tritech-tfsurl-control","uri":"index.html","height":90,"inputs":[{"id":"PreviousTFSServer","description":"The TFS server url that has the work item.","type":"WorkItemField","properties":{"workItemFieldTypes":["String"]},"validation":{"dataType":"String","isRequired":true}},{"id":"TFSCollection","description":"The original tfs collection name","type":"WorkItemField","properties":{"workItemFieldTypes":["String"]},"validation":{"dataType":"String","isRequired":true}},{"id":"TfsTeamProject","description":"Original TFS project name","type":"WorkItemField","properties":{"workItemFieldTypes":["String"]},"validation":{"dataType":"String","isRequired":true}},{"id":"TfsWorkItemId","description":"Original work item id","type":"WorkItemField","properties":{"workItemFieldTypes":["Integer"]}}],"::Attributes":16,"::Version":"0.1.20"}}
Thanks in advance.
I ended up using static values and got it working.
var Provider = () => {
this.ServerfieldName = "Source.Server";
this.CollectionfieldName = "Source.Collection";
this.ProjectfieldName = "Source.Project";
this.WorkItemIdfieldName = "Source.Id";
this._view = View;
return{
onLoaded: (WorkItemLoadedArgs: ExtensionContracts.IWorkItemLoadedArgs) => {
var deferred = Q.defer();
WorkItemFormService.getService().then(
(service) => {
Q.spread<any, any>(
[service.getFieldValue(this.ServerfieldName),service.getFieldValue(this.CollectionfieldName),
service.getFieldValue(this.ProjectfieldName),service.getFieldValue(this.WorkItemIdfieldName)],
(server: string, collection: string, project: string, workitemId: number) => {
var data =(`${server}/${collection}/${project}/_workitems#_a=edit&id=${workitemId}`);
if(server){
this._view = new View(data);
}
else{
$('body').empty().append("This is the original Work Item");
}
})
.catch(function (e) {deferred.reject(e)}
);
return deferred.promise; //.then(null);
}
)}
}
};
and used a view,
/// <reference path="../typings/index.d.ts" />
export class View {
constructor(public value:string) {
var Container = $("<div role='link'> </div>");
Container.addClass("Container");
Container.attr('tabindex', '0');
var rdiv = $("<div/>").addClass("rightDiv");
var ldiv = $("<div/>");
var help = $("<span></span>").text("Original Tfs work item ");
var a = $("<a> </a>");
a.attr("href", value);
a.attr("target", "_blank");
a.text("here.");
help.append(a);
ldiv.append(help);
Container.append(rdiv);
Container.append(ldiv);
$('body').empty().append(Container);
}
}

How to parse a nested json array in CI

i am trying to parse the following json
{
"offerinfo": {
"offername": "chaos",
"offertype": "3",
"brand": "1",
"subbrand": "0",
"categories": "1,2",
"Tags": "4,6",
"promotiontype": "1",
"currency": "1",
"promotioncode": "1",
"offertitle": "1",
"offerdescription": "ad",
"addtionalterms": "asdasd",
"retaildescription": "asdasd"
},
"media": {
"video": "",
"images": []
},
"availability": [
{
"airports": "1,4,6",
"stores": "3,4,5",
"startdate": "2014",
"enddate": "3434"
}],
"featured": {
"categories": "",
"slot": ""
}
}
COde for parsing is
$json = json_decode(trim(file_get_contents('php://input')),true);
//print_r($json)."<br/>";
//var_dump($json);
foreach($json as $key=>$value)
{
var_dump($value);
$offername = $value['offername']."<br/>";
//echo $media = $value['video'];
$mediaimage = $value['images'];
foreach($mediaimage as $a)
{
//echo $a['MediaFile'];
}
//echo $avail = $value['airports'];
echo $key->{'availability'};
//var_dump($avail);
// foreach($avail as $b)
// {
// echo $b['airports'];
//}
//var_dump($mediaimage);
}
i got the offername etc those in ogger info dictionary, but i am unable to parse the information from availability
can some one kindly help me
$json['availability'] is an array so you can access it like this
foreach ($json['availability'] as $availability) {
echo $availability["airports"];
// etc
}

Resources