Facebook Open Graph - Can "og.likes" action be assigned with "product" type? - facebook-graph-api

The following iOS code ("object" type with "og.likes" action) works just fine:
let properties = [
"og:type": "object",
"og:title": "Test Product",
"og:description": "Product description"
]
let object = FBSDKShareOpenGraphObject(properties: properties)
let action = FBSDKShareOpenGraphAction()
action.actionType = "og.likes"
action.setObject(object, forKey: "object")
let content = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName = "object"
FBSDKShareDialog.show(from: self, with: content, delegate: nil)
However, I prefer using "product" type rather than the generic "object" type. The following code is the same as the above one only replacing "object" with "product" (so this time trying to post a story about "product" type with "og.likes" action)
let properties = [
"og:type": "product",
"og:title": "Test Product",
"og:description": "Product description"
]
let object = FBSDKShareOpenGraphObject(properties: properties)
let action = FBSDKShareOpenGraphAction()
action.actionType = "og.likes"
action.setObject(object, forKey: "product")
let content = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName = "product"
FBSDKShareDialog.show(from: self, with: content, delegate: nil)
This code generated the following error:
Action Requires At Least One Reference: The action you’re trying to
publish is invalid because it does not specify any reference objects.
At least one of the following properties must be specified: object.
Any idea why?

Related

Terraform Variable looping to generate properties

I have to admit, this is the first time I have to ask something that I dont even myself know how to ask for it or explain, so here is my code.
It worth explains that, for specific reasons I CANNOT change the output resource, this, the metadata sent to the resource has to stay as is, otherwise it will cause a recreate and I dont want that.
currently I have a terraform code that uses static/fixed variables like this
user1_name="Ed"
user1_Age ="10"
user2_name="Mat"
user2_Age ="20"
and then those hard typed variables get used in several places, but most importanly they are passed as metadata to instances, like so
resource "google_compute_instance_template" "mytemplate" {
...
metadata = {
othervalues = var.other
user1_name = var.user1_name
user1_Age = var.user1_Age
user2_name = var.user2_name
user2_Age = var.user2_Age
}
...
}
I am not an expert on terraform, thus asking, but I know for fact this is 100% ugly and wrong, and I need to use lists or array or whatever, so I am changing my declarations to this:
users = [
{ "name" : "yo", "age" : "10", "last" : "other" },
{ "name" : "El", "age" : "20", "last" : "other" }
]
but then, how do i get around to generate the same result for that resource? The resulting resource has to still have the same metadata as shown.
Assuming of course that the order of the users will be used as the "index" of the value, first one gets user1_name and so on...
I assume I need to use a for_each loop in there but cant figure out how to get around a loop inside properties of a resource
Not sure if I make myself clear on this, probably not, but didn't found a better way to explain.
From your example it seems like your intent is for these to all ultimately appear as a single map with keys built from two parts.
Your example doesn't make clear what the relationship is between user1 and Ed, though: your first example shows that "user1's" name is Ed, but in your example of the data structure you want to create there is only one "name" and it isn't clear to me whether that name would replace "user1" or "Ed" from your first example.
Instead, I'm going to take a slightly different variable structure which still maintains both the key like "user1" and the name attribute, like this:
variable "users" {
type = map(object({
name = string
age = number
})
}
locals {
# First we'll transform the map of objects into a
# flat set of key/attribute/value objects, because
# that's easier to work with when we generate the
# flattened map below.
users_flat = flatten([
for key, user in var.users : [
for attr, value in user : {
key = key
attr = attr
value = value
}
]
])
}
resource "google_compute_instance_template" "mytemplate" {
metadata = merge(
{
othervalues = var.other
},
{
for vo in local.users_flat : "${vo.key}_${vo.attr}" => vo.value
}
)
}
local.users_flat here is an intermediate data structure that flattens the two-level heirarchy of keys and object attributes from the input. It would be shaped something like this:
[
{ key = "user1", attr = "name", value = "Ed" },
{ key = "user1", attr = "age", value = 10 },
{ key = "user2", attr = "name", value = "Mat" },
{ key = "user2", attr = "age", value = 20 },
]
The merge call in the metadata argument then merges a directly-configured mapping of "other values" with a generated mapping derived from local.users_flat, shaped like this:
{
"user1_name" = "Ed"
"user1_age" = 10
"user2_name" = "Mat"
"user2_age" = 20
}
From the perspective of the caller of the module, the users variable should be defined with the following value in order to get the above results:
users = {
user1 = {
name = "Ed"
age = 10
}
user2 = {
name = "Mat"
age = 20
}
}
metadata is not a block, but a regular attribute of type map. So you can do:
# it would be better to use map, not list for users:
variable "users"
default {
user1 = { "name" : "yo", "age" : "10", "last" : "other" },
user2 = { "name" : "El", "age" : "20", "last" : "other" }
}
}
resource "google_compute_instance_template" "mytemplate" {
for_each = var.users
metadata = each.value
#...
}

Unable to extract a value from a JSON response to use as an enviroment variable in Postman

Pre Request:
//Create random number
let randomNum =
Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
//Set Random # as the Random ID
pm.environment.set("randomNum", randomNum);
Body:
{
"AccountNumber": "AA{{randomNum}}",
"Name": "AA {{randomNum}}",
"Reference": "AA 01",
"VatCodeId": 1,
"UserCreated": "James"
}
Response:
{
"Id": 18,
"AccountNumber": "AA7e40",
"Name": "AA 7e40",
"Reference": "AA 01",
"VatCodeId": 1,
"DateCreated": "2022-01-27T09:53:43.6734454+00:00",
"UserCreated": "James"
}
Note: The Id field is being created when a 200 response is being returned, this is unique to the DB and increments by 1 for every new account created.
I am trying to extract the Id and use that as a Enviroment variable so it can be chained (for deletion of accounts). The Test script is:
var accountUniqueId = JSON.parse(responseBody);
pm.environment.set("accountId", json.result.data.Id);
Though I have tried variations of it such as:
var accountUniqueId = pm.response.json();
pm.environment.set("accountId", jsonData.Id);
var accountUniqueId = pm.response.json();
pm.environment.set("accountId", jsonData.response.Id);
The response in the Test is showing as:
There was an error in evaluating the test script: ReferenceError: json is not defined
The Enviroment Variable is being created with a current value of:
[object Object].
This should do it:
let jsonData= pm.response.json();
pm.environment.set("accountId", jsonData.Id);

Terrraform list of objects syntax

I'm using a module that references a central module used to build a Puppet server in terraform. There is one variable in the root module that allows additional tags to be used with the ASG however I can't seem to get the syntax right. This is the information in the core repository:
variable "additional_asg_tags" {
description = "A map of additional tags to add to the puppet server ASG."
type = list(object({ key = string, value = string, propagate_at_launch = bool }))
default = []
}
I've tried everything I can think of to call this but it always errors with messages like "incorrect list element type: string required." or "This default value is not compatible with the variable's type constraint: list of object required."
I'm trying to call the above with something like;
variable "additional_asg_tags" {
description = "A map of additional tags to add to ASG."
type = list(object({ key = string, value = string, propagate_at_launch = bool }))
default = { key = "Name", value = "Puppet-nonprod", propagate_at_launch = "true"
}
}
I've removed the square braces around this as that was causing errors also but I may need to add these back in.
Can someone help please in what is the correct way to reference a list of objects with these values
The correct default value for your additional_asg_tags is a list:
variable "additional_asg_tags" {
description = "A map of additional tags to add to ASG."
type = list(object({
key = string,
value = string,
propagate_at_launch = bool
}))
default = [{
key = "Name",
value = "Puppet-nonprod",
propagate_at_launch = "true"
}]
}
You can reference individual elements as follows (some examples):
var.additional_asg_tags[0]["key"]
var.additional_asg_tags[0].value
# to get list
var.additional_asg_tags[*].propagate_at_launch

how to create a list <> in flutter from Firestore?

I am new to flutter.
How can I retrieve data from Firestore and form a new profile with every child in my collection? Second question is how can I use this list in another dart file? thank you
Thank you.
final List<Profile> demoProfiles = [
Profile (
photos: [
"https://",
],
name: "abc",
),
Profile (
photos: [
"https://",
],
name: "abc",
)
];
Assuming you have a firestore strucuture like this:
Profile
photos: []
name: ""
age: ""
distance: ""
education: ""
You can fetch data and build it into your object with this code snippet:
fetchData() async{
final db = await Firestore.instance;
List<Profile> demoProfiles = []
db.collection("Profile").get().then(function(snapshot){
snapshot.forEach((document) {
demoProfiles.add(Profile(
photos: document.data.photos,
name: document.data.name,
age: document.data.age,
distance: document.data.distance,
education: document.data.education
))
})
})
}
Edit:
1) Remove the mockedup list of profiles from your profiles class, it should not be there
2) Edit your mainController to the following:
class _MainControllerState extends State<MainController> {
List<Profile> demoProfiles = [];
demoProfiles = fetchData();
Final MatchEngine match Engine = MatchEngine (
matches:demoProfiles.map((Profile profile) => Match(profile: profile)).toList();
);
fetchData() async{
final db = await Firestore.instance;
List<Profile> list = [];
db.collection("Profile").get().then(function(snapshot){
snapshot.forEach((document) {
list.add(Profile(
photos: document.data.photos,
name: document.data.name,
age: document.data.age,
distance: document.data.distance,
education: document.data.education
))
})
});
return list;
}
}

Type error when processing graphql result

I just started playing with reasonML and graphql and have built a simple react component that retrieves data from a world cup API. My code is below:
[#bs.module] external gql: ReasonApolloTypes.gql = "graphql-tag";
module GetMatches = [%graphql
{|
query getMatches($id: ID!){
matches(id: $id) {
date
homeTeam {name}
awayTeam {name}
homeScore
awayScore
goals {
scorer {
name
}
time
}
}
}
|}
];
module GetMatchesQuery = ReasonApollo.CreateQuery(GetMatches);
let component = ReasonReact.statelessComponent("Matches");
let make = _children => {
...component,
render: _self => {
let matchParam = GetMatches.make(~id="300331511", ());
<GetMatchesQuery variables=matchParam##variables>
...{
({result}) =>
switch (result) {
| Loading => <div> {ReasonReact.string("Loading")} </div>
| Error(error) =>
<div> {ReasonReact.string(error##message)} </div>
| Data(response) => <Matches matches=response##matches />
}
}
</GetMatchesQuery>;
},
};
Matches Component
let component = ReasonReact.statelessComponent("Matches");
let make = (~matches, _children) => {
...component,
render: _self =>
<div>
{
matches
|> Js.Array.map(match => <Match match key=match##id />)
|> ReasonReact.array
}
</div>,
};
But I'm getting this error:
This has type:
option(Js.Array.t(option({. "awayScore": option(int),
"awayTeam": option({. "name": option(string)}),
"date": option(string),
"goals": option(Js.Array.t(option({. "scorer":
option(
{. "name":
option(
string)}),
"time":
option(
string)}))),
"homeScore": option(int),
"homeTeam": option({. "name": option(string)})})))
But somewhere wanted:
Js.Array.t(Js.t(({.. id: string} as 'a))) (defined as array(Js.t('a)))
I added Js.log(response##matches); and got this in the console
I'm pretty sure there's some context missing here, and that you have something like open Belt at the top of your file.
The type error says response##matches is an array in an option, but also that the array elements themselves are in options, which is super weird. So my theory is that the code generated by graphql-ppx uses something like array indexing, which translates to a call to Array.get that in the standard library throws an exception if out of bounds, but in Belt, and many other standard libraries replacements, returns an option.
This is one of many problems with using ppxs. It generates code not in isolation and can interact weirdly with the rest of your code, and it's not easy to debug.