My restFB code results in writing on one App to my ArrayList. I need the arraylist to fill out properly with the number of appIds return in JSON. Any insights?
Here is my code:
public List<String> fetchAppIdsForUser() {
Connection<FacebookApp> appList = getClient().fetchConnection("me/applications/developer", FacebookApp.class);
List<String> appIds = new ArrayList<String> ();
for (List<FacebookApp> appListTwo : appList) {
for (FacebookApp app : appListTwo) {
appIds.add(app.getAppId());
}
}
return appIds;
}
And here is what is returned in JSON:
{
"data": [
{
"name": "x",
"namespace": "x",
"id": "x"
},
{
"name": "xx",
"namespace": "xx",
"id": "xx"
},
{
"name": "xxx",
"namespace": "xxxx",
"id": "xxxxx"
},
{
"name": "xxxx",
"namespace": "xxxxx",
"id": "xxxxx"
}
],
"paging": {
"next": "https://graph.facebook.com/xxxxx/applications?type=developer&format=json&access_token=XXXXXXXX"
}
}
I solved it using the following:
public List<String> fetchAppIdsForUser() {
Connection<FacebookApp> appList = getClient().fetchConnection("me/applications/developer", FacebookApp.class);
List<FacebookApp> list = appList.getData();
ArrayList<String> appNames = new ArrayList<String>();
for (FacebookApp app: list) {
appNames.add(app.getName());
}
return appNames;
}
Related
Consider the following data structure:
{
"company": {
"idCompany1": {
"data": {
"address": "",
"companyName": "Company 1",
"logo": "assets/Logo1.png",
"nit": "",
"phone": ""
}
},
"idCompany2": {
"data": {
"address": "",
"companyName": "Company 2",
"logo": "assets/Logo2.png",
"nit": "",
"phone": ""
}
},
"idCompany3": {
"data": {
"address": "",
"companyName": "Company 3",
"logo": "assets/Logo3.png",
"nit": "",
"phone": ""
}
}
},
"users": {
"idUser1": {
"data": "user1#test.com",
"companies": {
"idCompany1": true,
"idCompany3": true
}
},
"idUser2": {
"data": "user2#test.com",
"companies": {
"idCompany2": true
}
}
}
}
Basically what I need to do in the case of user1 is to read the data of the companies to which it belongs, this is Company 1 and Company 3. How can I do that?
The way I found, is by obtaining a list of IDs of those companies, which I have in listaIdEmpresas and then consulting each one through a forEach loop in the following way:
Future<List<EmpresaDatosModel>> cargarEmpresaDatosListado(List<String> listaIdEmpresas) async {
final List<EmpresaDatosModel> listaEmpresas = new List();
listaIdEmpresas.forEach((id) async {
Query resp = db.child('company/$id/data');
final snapshot = await resp.once();
final temp = EmpresaDatosModel.fromJson(Map<String,dynamic>.from(snapshot.value));
temp.idEmpresa = id;
listaEmpresas.add(temp);
print('${temp.companyName} up');
await resp.once().then((snapshot) {});
});
listaEmpresas.forEach((element) {print('Emp ${element.companyName}');});
return listaEmpresas;
}
However, this process is not efficient and I need to manage a delay for waiting the loop.
What would be the right way to do query data from a list of Ids directly?
I am working on trying to correctly document our rest endpoints. As an example to get this working I created a sample "Healthcheck getStatus()" endpoint which is returning an object called "EndpointStatus" which has 3 fields (class is below). I was able to get this object documenting correctly and using the camel-swagger-java component and the below rest configuration / definition;
restConfiguration()
.apiContextPath(apiContextPath)
.apiProperty("api.title", "Camel Service").apiProperty("api.version", "1.0.0")
// and enable CORS
.apiProperty("cors", "true");
rest()
.path("/healthcheck")
.description("Health Check REST service")
.get("getStatus/{endpointName}")
.param()
.name("endpointName")
.type(RestParamType.path)
.allowableValues(
Stream.of(EndpointName.values())
.map(EndpointName::name)
.collect(Collectors.toList()))
.required(true)
.endParam()
.description("Get Camel Status")
.id("getStatus")
.outType(EndpointStatus.class)
.bindingMode(RestBindingMode.auto)
.responseMessage().code(200).message("Returns an EndpointStatus object representing state of a camel endpoint").endResponseMessage()
.to(CAMEL_STATUS_URI);
Here are the annotations I used on this class:
#ApiModel(description = "Endpoint Status Model")
public class EndpointStatus {
private boolean isAvailable;
private EndpointName name;
private long timestamp;
#ApiModelProperty(value = "Is the endpoint available", required = true)
public boolean isAvailable() {
return isAvailable;
}
public void setAvailable(boolean available) {
isAvailable = available;
}
#ApiModelProperty(value = "The name of the endpoint", required = true)
public EndpointName getName() {
return name;
}
public void setName(EndpointName name) {
this.name = name;
}
#ApiModelProperty(value = "The timestamp the endpoint was checked", required = true)
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}
Along with the generated swagger documentation:
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Camel Service"
},
"host": "localhost:9000",
"tags": [
{
"name": "healthcheck",
"description": "Health Check REST service"
}
],
"schemes": [
"http"
],
"paths": {
"/healthcheck/getStatus/{endpointName}": {
"get": {
"tags": [
"healthcheck"
],
"summary": "Get Camel Status",
"operationId": "getStatus",
"parameters": [
{
"name": "endpointName",
"in": "path",
"required": true,
"type": "string",
"enum": [
"ENDPOINTA",
"ENDPOINTB"
]
}
],
"responses": {
"200": {
"description": "Returns an EndpointStatus object representing state of a camel endpoint",
"schema": {
"$ref": "#/definitions/EndpointStatus"
}
}
}
}
}
},
"definitions": {
"EndpointStatus": {
"type": "object",
"required": [
"available",
"name",
"timestamp"
],
"properties": {
"name": {
"type": "string",
"description": "The name of the endpoint",
"enum": [
"ENDPOINTA",
"ENDPOINTB"
]
},
"timestamp": {
"type": "integer",
"format": "int64",
"description": "The timestamp the endpoint was checked"
},
"available": {
"type": "boolean",
"description": "Is the endpoint available"
}
},
"description": "Endpoint Status Model"
}
}
}
However, when trying to move to use camel-openapi-java which supports OpenAPI Specification v3 with the same setup I am getting EndpointStatus without any fields / descriptions in my documentation.
{
"openapi": "3.0.2",
"info": {
"title": "SurePath Camel Service",
"version": "1.0.0"
},
"servers": [
{
"url": ""
}
],
"paths": {
"/healthcheck/getStatus/{endpointName}": {
"get": {
"tags": [
"healthcheck"
],
"parameters": [
{
"name": "endpointName",
"schema": {
"enum": [
"ENDPOINTA",
"ENDPOINTB"
],
"type": "string"
},
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Returns an EndpointStatus object representing state of a camel endpoint"
}
},
"operationId": "getStatus",
"summary": "Get Camel Status",
"x-camelContextId": "camel-1",
"x-routeId": "getStatus"
}
},
"/healthcheck/isAvailable": {
"get": {
"tags": [
"healthcheck"
],
"responses": {
"200": {
"description": "Returns status code 200 when Camel is available"
}
},
"operationId": "verb1",
"summary": "Is Camel Available",
"x-camelContextId": "camel-1",
"x-routeId": "route4"
}
}
},
"components": {
"schemas": {
"EndpointStatus": {
"type": "EndpointStatus",
"x-className": {
"format": "com.sample.bean.EndpointStatus",
"type": "string"
}
}
}
},
"tags": [
{
"name": "healthcheck",
"description": "Health Check REST service"
}
]
}
I have tried adding this into my responseMessage and it is still not documenting correctly;
responseMessage().code(200).responseModel(EndpointStatus.class).message("Returns an EndpointStatus object representing state of a camel endpoint").endResponseMessage()
Do I need different annotations / RestDefinition config to get this EndpointStatus class appearing correctly in the OpenAPI documentation?
This looks to be an issue at the moment with the camel-openapi-java component; waiting for a resolution from this jira https://issues.apache.org/jira/browse/CAMEL-15158
I am new to Scala and protobufs. I want to create a object something like this
{
"id": "usr-435-899",
"type": "SALES",
"filters": {
"country": [
"usa",
"germany"
],
"indication": [
"delivery"
]
}
}
So I think I cannot create the POJO like this in protobuf's.
Now I've created different JSON which is
{
"id": "usr-435-899",
"type": "SALES",
"filters": {
"country": {
"value": [
"usa",
"germany"
]
},
"indication": {
"value": [
"delivery"
]
}
}
}
So I've created a proto something like this:
message ListOfValues {
repeated string value = 1;
}
message AuditRequest {
required string id = 1;
required string type = 2;
map<string, ListOfValues> filters = 3;
}
But when I try to hit the api from POSTMAN it says 404 not found
Can anyone tell whats wrong in this? And Can we create proto for first JSON?
I was connected my chatbot to google assistant action. They give only the userID, how to get username by using this userID?
You can get username without knowing userid, by the permissions document here. You can take a look at this sample code.
Or you can use account linking feature.
Tip! for userID, you can check out this doc
For Python:
There is no official library for developing google action using Python but,
You can add permission intent in possibleIntent array. So your Action SDK JSON will be,
{
"expectUserResponse": true,
"expectedInputs": [
{
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "PLACEHOLDER"
}
}
]
}
},
"possibleIntents": [
{
"intent": "actions.intent.PERMISSION",
"inputValueData": {
"#type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
"optContext": "To address you by name and know your location",
"permissions": [
"NAME",
"DEVICE_PRECISE_LOCATION"
]
}
}
]
}
],
"conversationToken": "{\"data\":{}}",
"userStorage": "{\"data\":{}}"
}
{`"actions": [
{
"description": "Default Welcome Intent",
"name": "MAIN",
"fulfillment": {
"conversationName": "welcome"
},
"intent": {
"name": "actions.intent.MAIN",
"trigger": {
"queryPatterns":["talk to Mr Bot"]
}
}
},
{
"description": "Rasa Intent",
"name": "TEXT",
"fulfillment": {
"conversationName": "rasa_intent"
},
"intent": {
"name": "actions.intent.TEXT",
"trigger": {
"queryPatterns":[]
}
}
}],
"conversations": {
"welcome": {
"name": "welcome",
"url": "https://ac752bb0.ngrok.io/webhooks/google_home/webhook",
"fulfillmentApiVersion": 2
},
"rasa_intent": {
"name": "rasa_intent",
"url": "https://ac752bb0.ngrok.io/webhooks/google_home/webhook",
"fulfillmentApiVersion": 2
}
} }
this is my action.json,
class GoogleConnector(InputChannel):
#classmethod
def name(cls):
return "google_home"
#def __init__(self):
# self.out_channel = CustomOutput(url, access_token)
def blueprint(self, on_new_message):
google_webhook = Blueprint('google_webhook', __name__)
#google_webhook.route("/", methods=['GET'])
def health():
return jsonify({"status": "ok"})
#google_webhook.route("/webhook", methods=['POST'])
def receive():
payload = json.loads(request.data)
sender_id = payload['user']['userId']
intent = payload['inputs'][0]['intent']
text = payload['inputs'][0]['rawInputs'][0]['query']
if intent == 'actions.intent.MAIN':
message = "<speak>Hello! <break time=\"1\"/> Welcome to the Rasa-powered Google Assistant skill. You can start by saying hi."
else:
out = CollectingOutputChannel()
on_new_message(UserMessage(text, out, sender_id))
responses = [m["text"] for m in out.messages]
message = responses[0]
r = json.dumps(
{
"conversationToken": "{\"state\":null,\"data\":{}}",
"expectUserResponse": 'true',
"expectedInputs": [
{
"inputPrompt": {
"initialPrompts": [
{
"ssml": message
}
]
},
"possibleIntents": [
{
"intent": "actions.intent.TEXT"
}
]
}
]
})
return r
return google_webhook
this my google connector python code,
how to modified this for account signin
When I try to deploy a sample contract to the Azure Blockchain Workbench:
The ContractUpdated call in function dispose of contract Contract has a parameter 'Only the contract owner can dispose of the contract.' which is a function name not defined in the set of functions for the workflow.
The text is actually a message in a require statement and has nothing to do with functions in workflows.
This is my contract:
pragma solidity ^0.4.24;
contract WorkbenchBase {
event WorkbenchContractCreated(string applicationName, string workflowName, address originatingAddress);
event WorkbenchContractUpdated(string applicationName, string workflowName, string action, address originatingAddress);
string internal ApplicationName;
string internal WorkflowName;
constructor(string memory applicationName, string memory workflowName) internal
{
ApplicationName = applicationName;
WorkflowName = workflowName;
}
function ContractCreated() internal
{
emit WorkbenchContractCreated(ApplicationName, WorkflowName, msg.sender);
}
function ContractUpdated(string memory action) internal
{
emit WorkbenchContractUpdated(ApplicationName, WorkflowName, action, msg.sender);
}
}
contract Contract is WorkbenchBase("Contract", "Contract")
{
enum StateType
{
New,
Disposed
}
address public owner;
StateType public state;
constructor() public
{
owner = msg.sender;
state = StateType.New;
ContractCreated();
}
function destroy() public
{
require(msg.sender == owner, "Only the contract owner can destroy the contract.");
selfdestruct(owner);
}
function dispose() public
{
require(msg.sender == owner, "Only the contract owner can dispose of the contract.");
state = StateType.Disposed;
ContractUpdated('dispose');
}
}
And this is my JSON file:
{
"Id": 1,
"ApplicationName": "Contract",
"DisplayName": "Contract",
"Description": "",
"ApplicationRoles": [
{
"Name": "Representative"
}
],
"Workflows": [
{
"Id": 1,
"Name": "Contract",
"DisplayName": "Contract",
"Initiators": [
"Representative"
],
"StartState": "New",
"Properties": [
{
"Id": 1,
"Name": "state",
"DisplayName": "State",
"Description": "Holds the state.",
"Type": {
"Name": "state"
}
},
{
"Id": 2,
"Name": "owner",
"DisplayName": "Owner",
"Description": "Holds the address of the owner of the contract.",
"Type": {
"Name": "address"
}
}
],
"Constructor": {
"Parameters": []
},
"Functions": [
{
"Id": "1",
"Name": "dispose",
"DisplayName": "Dispose",
"Description": "Disposes the contract.",
"Parameters": []
},
],
"States": [
{
"Id": 1,
"Name": "New",
"DisplayName": "New",
"PercentComplete": 0,
"Value": "New",
"Style": "Success",
"Transitions": [
{
"AllowedRoles": [
"Representative"
],
"AllowedInstanceRoles": [],
"Description": "Disposes the contract.",
"Function": "dispose",
"NextStates": [
"Disposed"
],
"DisplayName": "Dispose"
}
]
},
{
"Id": 100,
"Name": "Disposed",
"DisplayName": "Disposed",
"PercentComplete": 100,
"Value": "Disposed",
"Style": "Failure",
"Transitions": []
}
]
}
]
}
Is this a bug in Azure Blockchain Workbench or am I doing something wrong?