This is an extension of this question here:
Getting Facebook Events using fql
I am running into the problem when there is no location/venue set for the events.
Here is the query I am using:
{\"events\":
\"SELECT eid, name,description, start_time, end_time, pic_small,pic_big, eid,venue,location
from event WHERE eid in (SELECT eid FROM event_member WHERE uid = me()
and start_time > %s)\" ,
\"locations\":
\"select page_id,location from page where page_id IN
(select venue.id from #events)\" ,
\"rsvpStatus\":
\"select eid, rsvp_status from event_member where eid IN
(select eid from #events) AND uid = me()\" }
My observation : when there is location set for this event, the venue atttibute is a json object with and id property. Please refer below json
{
"eid": 34343434322,
"name": "Another yo you",
"description": "",
"start_time": 1347699600,
"end_time": 1347786000,
"pic_small": "http:\/\/profile.ak.fbcdn.net\/static-ak\/rsrc.php\/v2\/yy\/r\/XcB-JGXohjk.png",
"pic_big": "http:\/\/profile.ak.fbcdn.net\/static-ak\/rsrc.php\/v2\/yn\/r\/5uwzdFmIMKQ.png",
"venue": {
"id": 34243242
},
"location": "Airbiquity"
}
When there is no location set, it is an empty array. Please refer below json.
{
"eid": 441320552577649,
"name": "Meeting",
"description": "",
"start_time": 1347491700,
"end_time": 1347502500,
"pic_small": "http:\/\/profile.ak.fbcdn.net\/static-ak\/rsrc.php\/v2\/yy\/r\/XcB-JGXohjk.png",
"pic_big": "http:\/\/profile.ak.fbcdn.net\/static-ak\/rsrc.php\/v2\/yn\/r\/5uwzdFmIMKQ.png",
"venue": [
],
"location": null
}
It's weird that the type of the venue attribute changes. I am GSON to convert this response for Java object and it's throwing off due to unepected structure for venue.
Can someone help me with this issue?
Facebook's treatment of venues has changed this past May. There are several different situations I've get returned by the API, depending on when and how the event was created.
The id of a known venue is returned.
The venue field is blank and an arbitrary location string is returned.
Venue contains an array of information about the event venue, but no id.
Unfortunately, your script has to deal with all of these cases and be ready for whatever future cases the Facebook engineers may come up with.
Related
I trying to create a new conversation with person or group of persons, so I create a Bearer token for authentication and add it to header as bearer token (in postman).
So on the next step I create a json script that, theoretically, can create a new conversation. I trying to create a conversation with several person or with only one (for it I added a several person to members or one and change flag isGroup to true or false).
This is a example of json for 1 person:
{
"bot": {
"id": "<app id>",
"name": "<bot name>"
},
"isGroup": false,
"members": [
{
"id": "<member id>",
"name": "<member name>"
}
],
"topicName": "Hello there!"
}
Member id is correct for all members that I trying to add in a new conversation.
And the next response I get always:
{
"id": "8:live:<skype account name>"
}
For group conversation I get the this live skype name for first person that I added. All requests was send to https://skype.botframework.com/v3/conversations or https://smba.trafficmanager.net/apis/v3/conversations and response always same.
Can someone tell me what I'm doing wrong?
Also if I add Activity in body like:
"activity":
{
"type": "message",
"from":
{
"id": "<app-id>",
"name": "<bot name>"
},
"recipient":
{
"id": "<member id>",
"name": "<member name>"
},
"text": "HI"
}
I get next response:
{
"error":
{
"code": "ServiceError",
"message": "Unknown"
}
}
Because Skype only allows one conversation between any two given users, what looks like a simple user ID is actually enough for the Bot Framework to identify the conversation. Some channels, Skype included, allow more than one ID format. In the case of Skype, each conversation can be identified in two ways:
< number >:< Skype screen name >
< number >:< base64 string >
For example, when I create a conversation in Skype, I get the ID 8:kyle-delaney. I can use that to send a message to the conversation with the following endpoint:
https://smba.trafficmanager.net/apis/v3/conversations/8:kyle-delaney/activities
However, when my bot receives a message from the user, both the conversation ID and the "from" ID will be 29:1CpqzpVMMhfi_2nyS1g2mfHaCxnvGL0sF8LbnGadyR_Y. So I can also send a message to the same conversation using this endpoint:
https://smba.trafficmanager.net/apis/v3/conversations/29:1CpqzpVMMhfi_2nyS1g2mfHaCxnvGL0sF8LbnGadyR_Y/activities
I have a table called Group and it will have records like:
{
"id": "UniqueID1",
"name": "Ranjeeth",
"emailIdMappings": [
{
"emailId": "r.pt#r.com",
"userId": 324
},
{
"emailId": "r1.pt#r.com",
"userId": 325
}
]
},
{
"id": "UniqueID2",
"name": "Ranjeeth",
"emailIdMappings": [
{
"emailId": "r1.pt#r.com",
"userId": 325
},
{
"emailId": "r2.pt#r.com",
"userId": 326
}
]
}
I need to query and get result if emailId contains the input string.
I have reached so far and I am not able to get the result
AttributeValue attributeValue = new AttributeValue("r.pt#r.com");
Condition containsCondition = new Condition()
.withComparisonOperator(ComparisonOperator.CONTAINS)
.withAttributeValueList(attributeValue);
Map<String, Condition> conditions = newHashMap();
conditions.put("emailIdMappings.emailId", containsCondition);
ScanRequest scanRequest = new ScanRequest()
.withTableName("Group")
.withScanFilter(conditions);
amazonDynamoDB.scan(scanRequest)
dynamoDBMapper.marshallIntoObjects(Group.class, scanResult.getItems());
For the above code I am expecting record with id UniqueID1, but it's empty. If you pass "r1.pt#r.com" then you should get both records.
sdk used is com.amazonaws:aws-java-sdk-dynamodb:1.11.155
I tried posting the question in aws forum which didn't help much.
As you have List of Objects which has two attributes in a object (i.e. emailId and userId), you need to provide both values in order to match the item.
The CONTAINS function will not be able to match the item if the object has two attributes and only one attribute value mentioned in the filter expression.
Otherwise, you need to provide the occurrence (i.e. index) of the list to match the item.
Example:-
emailIdMappings[0].emailId = :emailIdVal
Is there a way so that I get only the data present in _source of my Document & not any other metadata like _index,_type,_id,_score while retrieving it from Index?
I got it how to do it.
GET /<index>/<type>/<id>/_source
will return only _source field.
Example:
Create a document with ID 123
PUT /website/blog/123
{
"title": "My first blog entry",
"text": "Just trying this out...",
"date": "2014/01/01"
}
To Retrieve just the _source field
GET /website/blog/123/_source
returned:
{
"title": "My first blog entry",
"text": "Just trying this out...",
"date": "2014/01/01"
}
I am using Java API for CRUD operation on elasticsearch.
I have an typewith a nested field and I want to update this field.
Here is my mapping for the type:
"enduser": {
"properties": {
"location": {
"type": "nested",
"properties":{
"point":{"type":"geo_point"}
}
}
}
}
Of course my enduser type will have other parameters.
Now I want to add this document in my nested field:
"location":{
"name": "London",
"point": "44.5, 5.2"
}
I was searching in documentation on how to update nested document but I couldn't find anything. For example I have in a string the previous JSON obect (let's call this string json). I tried the following code but seems to not working:
params.put("location", json);
client.prepareUpdate(index, ElasticSearchConstants.TYPE_END_USER,id).setScript("ctx._source.location = location").setScriptParams(params).execute().actionGet();
I have got a parsing error from elasticsearch. Anyone knows what I am doing wrong ?
You don't need the script, just update it.
UpdateRequestBuilder br = client.prepareUpdate("index", "enduser", "1");
br.setDoc("{\"location\":{ \"name\": \"london\", \"point\": \"44.5,5.2\" }}".getBytes());
br.execute();
I tried to recreate your situation and i solved it by using an other way the .setScript method.
Your updating request now would looks like :
client.prepareUpdate(index, ElasticSearchConstants.TYPE_END_USER,id).setScript("ctx._source.location =" + json).execute().actionGet()
Hope it will help you.
I am not sure which ES version you were using, but the below solution worked perfectly for me on 2.2.0. I had to store information about named entities for news articles. I guess if you wish to have multiple locations in your case, it would also suit you.
This is the nested object I wanted to update:
"entities" : [
{
"disambiguated" : {
"entitySubTypes" : [],
"disambiguatedName" : "NameX"
},
"frequency" : 1,
"entityType" : "Organization",
"quotations" : ["...", "..."],
"name" : "entityX"
},
{
"disambiguated" : {
"entitySubType" : ["a", "b" ],
"disambiguatedName" : "NameQ"
},
"frequency" : 5,
"entityType" : "secondTypeTest",
"quotations" : [ "...", "..."],
"name" : "entityY"
}
],
and this is the code:
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.index(indexName);
updateRequest.type(mappingName);
updateRequest.id(url); // docID is a url
XContentBuilder jb = XContentFactory.jsonBuilder();
jb.startObject(); // article
jb.startArray("entities"); // multiple entities
for ( /*each namedEntity*/) {
jb.startObject() // entity
.field("name", name)
.field("frequency",n)
.field("entityType", entityType)
.startObject("disambiguated") // disambiguation
.field("disambiguatedName", disambiguatedNameStr)
.field("entitySubTypes", entitySubTypeArray) // multi value field
.endObject() // disambiguation
.field("quotations", quotationsArray) // multi value field
.endObject(); // entity
}
jb.endArray(); // array of nested objects
b.endObject(); // article
updateRequest.doc(jb);
Blblblblblblbl's answer couldn't work for me atm, because scripts are not enabled in our server. I didn't try Bask's answer yet - Alcanzar's gave me a hard time, because I supposedly couldn't formulate the json string correctly that setDoc receives. I was constantly getting errors that either I am using objects instead of fields or vice versa. I also tried wrapping the json string with doc{} as indicated here, but I didn't manage to make it work. As you mentioned it is difficult to understand how to formulate a curl statement at ES's java API.
A simple way to update the arraylist and object value using Java API.
UpdateResponse update = client.prepareUpdate("indexname","type",""+id)
.addScriptParam("param1", arrayvalue)
.addScriptParam("param2", objectvalue)
.setScript("ctx._source.field1=param1;ctx._source.field2=param2").execute()
.actionGet();
arrayvalue-[
{
"text": "stackoverflow",
"datetime": "2010-07-27T05:41:52.763Z",
"obj1": {
"id": 1,
"email": "sa#gmail.com",
"name": "bass"
},
"id": 1,
}
object value -
"obj1": {
"id": 1,
"email": "sa#gmail.com",
"name": "bass"
}
Although it is possible to create album from the following privacy settings of Facebook,
the following error occurs if I use GraphAPI.
There is no specific description about the restriction in the API.
Please let me know if you have any idea to create the album from GraphAPI.
http://developers.facebook.com/docs/reference/api/album/
-the parameters to create album
name: albumName
privacy: {"value": "CUSTOM", "friends": "SOME_FRIENDS", "networks": "", "allow": "xxxxxxx", "deny": "yyyyyyyyy"}
allow:id of the particular friend (xxxxxxx)
deny: id of the family (yyyyyyyyy)
-Error Reason
"error": {
"message":, "An unknown error has occurred."
"type": "OAuthException",
"code": 1
}
May You try this:
$page_token = $facebook->api('/'.$page['id'],'GET',array('fields'=> 'access_token'));
$facebook->setAccessToken($page_token['access_token']);
$page_id = $page['id'];
$facebook->setFileUploadSupport(true);
$album_args = array(
'message'=> 'test album',
'name'=> 'Test Album'
);
try{
$album = $facebook->api('/me/albums?access_token='.YOUR_ACCESS_TOKEN_HERE,'POST', $album_args);
print_r($album);
$albumID = $album['id'];
}
catch(FacebookApiException $ex){
echo $ex;
}
This should create an album on YOUR profile!