How to get multiple avatars in only 1 request using Facebook API - facebook

I developed a method for get (doing http requests) the facebook avatars of my friends and convert each image as Sprite. If I have 5 friends i'm doing 5 requests. It worked some months ago. But now it doesn't work. I receive a 'time out' response when I try to get the second avatar.
I suppose that this problem is related to the quantity of requests that i'm doing. Maybe Facebook has a new 'flood protection'.
So, now, i'm trying to make an only one http request for obtain ALL avatars at the same time. In the official documentation (https://developers.facebook.com/docs/graph-api/making-multiple-requests) I read that I should use "Batch request" but the response that i'm getting doesn't contain the information for construct each image. How can I solve it?
Background:
C++ / cocos2d-x / class network::HttpRequest
network::HttpRequest* req = new network::HttpRequest();
req->setUrl("https://graph.facebook.com");
vector<string> header;
header.emplace_back("User-Agent: MyApp/1.0");
header.emplace_back("Content-Type: application/json");
req->setHeaders(header);
req->setRequestData(requestBody.c_str(), requestBody.length());
req->setRequestType(network::HttpRequest::Type::POST);
network::HttpClient::getInstance()->send(req);
requestBody content:
{
“batch”: [
{
“method”: GET
“relative_url”: http://…url to the direct download to avatar-image
},
{
“method”: GET
“relative_url”: http://…url to the direct download to avatar-image
}
],
“access_token”: “…”
}
(All of the relative_url works because I tested it in a browser)
Example of data response that I'm receiving:
[{
“code”: 200,
“headers”: [{
“name”: “Expires”,
“value”: “Sat, 01 Jan 2000 00:00:00 GMT”
}, {
“name”: “Cache-Control”,
“value”: “private, no-cache, no-store, must-revalidate”
}, {
“name”: “Access-Control-Allow-Origin”,
“value”: “ "
}, {
“name”: “Pragma”,
“value”: “no-cache”
}, {
“name”: “Strict-Transport-Security”,
“value”: “max-age=15552000; preload”
}, {
“name”: “ETag”,
“value”: ““3f2ef278dacb9dfc1c3827404a99ad8dfedc20cd””
}, {
“name”: “Vary”,
“value”: “Accept-Encoding”
}, {
“name”: “X-App-Usage”,
“value”: “{“call_count”:10,“total_cputime”:0,“total_time”:0}”
}, {
“name”: “Content-Type”,
“value”: “text/javascript; charset=UTF-8”
}, {
“name”: “Facebook-API-Version”,
“value”: “v2.12”
}],
“body”: “{“id”:“https://platform-lookaside.fbsbx.com/platform/profilepic”}”
}]
With that response I don't have the information for construct an image-sprite. Example of the responseData that I need for construct 1 sprite-image: \377\330\377\340

Related

VSCode REST Client Extension - Loop Request

I have the requirement to send nearly the same POST request to a backend system several times - say 50 times.
Is there a way to put the below request into a loop?
###
#POST Gamer
POST {{hostURL}}/api/Gamer
Content-Type: application/json
{
"username": "User-{{$randomInt 3 1000}}",
"characters": [
{
"name": "Superman",
"rpgClass": "Attacker",
"weapon": {
"name": "Flying",
"damage": 100
},
"characterSkill": [
{
"skillId": 1
},
{
"skillId": 2
}
]
}
]
}

How to create multiple entities using a single OData POST to a Business Central Web Service?

I tried to POST an array of objects and, as expected, it isn't that easy. In my case I want to insert multiple Transfer Order Lines in the same request.
// Request Body
[
{
"documentNo": "1002",
"itemNo": "1968-S",
"quantity": 3
},
{
"documentNo": "1002",
"itemNo": "1968-S",
"quantity": 113
}
]
// Response
{
"error": {
"code": "BadRequest",
"message": "Invalid Request Body CorrelationId: a2606676-3f8f-4753-aaee-be91a621f070."
}
}
Is it possible to do what I want without sending a request for every Line entity I want to add?
You need to create a structure like this:
url: api/2.0/$batch
Body:
```lang-json
{
"requests":
[
{
"method": "POST",
"id":"R1",
"url": "companies(id)/APIEntitySetName",
"headers":
{
"content-Type": "application/json"
},
"body":
{}
},
{
another line
}
]
}
```

Why I do not receive the attachments in the Facebook Messenger webhook request?

Since yesterday (29/10/2020) i'm having this problem only on one of the pages linked to my app, the others work correctly:
The attached messages that the webhook receives from Facebook do not contain the attachment field.
Only messages with stickers contain the "attachment" field. All others (image, video, audio etc.) No.
What I expect (as facebook documentation) is:
{
"id": "682498302938465",
"time": 1518479195594,
"messaging": [
{
"sender": {
"id": "<PSID>"
},
"recipient": {
"id": "<PAGE_ID>"
},
"timestamp": 1518479195308,
"message": {
"mid": "mid.$cAAJdkrCd2ORnva8ErFhjGm0X_Q_c",
"attachments": [
{
"type": "<image|video|audio|file>",
"payload": {
"url": "<ATTACHMENT_URL>"
}
}
]
}
}
]
}
but I only receive:
{
"object": "page",
"entry": [
{
"id": "119320008135788",
"time": 1604051633128,
"messaging": [
{
"sender": {
"id": "XXXXXX"
},
"recipient": {
"id": "XXXXXX"
},
"timestamp": 1604051632953,
"message": {
"mid": "m_7DRP...."
}
}
]
}
]
}
This only happens on one page from 29/10/2020
Does anyone have the same problem / know why it happens?
The Facebook support team has confirmed my problem, and is investigating.
I am now solving using the graph api to get the desired message information using the mid
GET /v8.0/{message-id} HTTP/1.1
Host: graph.facebook.com
https://developers.facebook.com/docs/graph-api/reference/v8.0/message
Ex.
GET
https://graph.facebook.com/v8.0/' + mid + '?fields=message%2Cfrom%2Csticker%2Ctags%2Cid%2Cattachments.limit(10)%7Bid%2Cimage_data%2Cmime_type%2Cname%2Cfile_url%2Cvideo_data%7D&access_token=XXXXXX

Error trying to use an uploaded image in Linkedin

I'm trying to use the Linkedin API to share a post with an image. I've followed all the steps in the documentation:
https://learn.microsoft.com/es-es/linkedin/consumer/integrations/self-serve/share-on-linkedin?context=linkedin/consumer/context#share-media
First, I register the upload with a POST to https://api.linkedin.com/v2/assets?action=registerUpload and this body:
{
"registerUploadRequest": {
"recipes": [
"urn:li:digitalmediaRecipe:feedshare-image"
],
"owner": "urn:li:person:{{owner_ID}}",
"serviceRelationships": [
{
"relationshipType": "OWNER",
"identifier": "urn:li:userGeneratedContent"
}
]
}
}
I get this response:
{
"value": {
"uploadMechanism": {
"com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest": {
"uploadUrl": "https://api.linkedin.com/mediaUpload/C4E22AQF6AS1WhrD1lw/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQKLg3lSJnswAgAAAXSgLwWp6iAPzjh6E_5XQh8QuP1Aucf_j9bgW3m5vQ&app=74851466&sync=0&v=beta&ut=2h9vtCSeuP0ps1",
"headers": {
"media-type-family": "STILLIMAGE"
}
}
},
"asset": "urn:li:digitalmediaAsset:C4E22AQF6AS1WhrD1lw",
"mediaArtifact": "urn:li:digitalmediaMediaArtifact:(urn:li:digitalmediaAsset:C4E22AQF6AS1WhrD1lw,urn:li:digitalmediaMediaArtifactClass:feedshare-uploadedImage)"
}
}
Then I use the uploadURL to make another post with the image as body, and get a 201 Created response.
I've checked the upload with a GET https://api.linkedin.com/v2/assets/C4E22AQF6AS1WhrD1lw and it has been uploaded correctly:
{
"recipes": [
{
"recipe": "urn:li:digitalmediaRecipe:feedshare-image",
"status": "AVAILABLE"
}
],
"serviceRelationships": [
{
"relationshipType": "OWNER",
"identifier": "urn:li:userGeneratedContent"
}
],
"mediaTypeFamily": "STILLIMAGE",
"created": 1600415270252,
"id": "C4E22AQF6AS1WhrD1lw",
"lastModified": 1600415345915,
"status": "ALLOWED"
}
When I try to share a post referencing this image I get this error:
{"message":"com.linkedin.restli.server.RestLiServiceException [HTTP Status:401]: com.linkedin.content.common.ResponseException: Writers of type person are not authorized to modify UserGeneratedContent.","status":401}
I'm sending a POST to this URL https://api.linkedin.com/v2/ugcPosts with this body:
{
"author": "urn:li:person:{{person_id}}",
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"text": "Feeling inspired after meeting so many talented individuals at this year's conference. #talentconnect"
},
"shareMediaCategory": "IMAGE",
"media": [
{
"status": "READY",
"description": {
"text": ""
},
"media": "urn:li:digitalmediaAsset:C4E22AQF6AS1WhrD1lw",
"title": {
"text": ""
}
}
]
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
I can share an only text post without trouble, look at my person ID, even like a post, but I'm stuck with this.
Can anyone tell me what am I doing wrong?
Solved. I had an error in the person_id variable, so I was trying to create a post with the wrong id.

Facebook Registration Can't parse fields attribute. Is it a JSON array or CSV list error in IE

I am trying to use the facebook registration plugin. I have it working in Firefox and Chrome, but in IE I receive the 'Can't parse fields attribute. Is it a JSON array or CSV list?'
I've found though if I take off the last custom field is fine. I tried rearranging the field order, but whenever I have over 10 fields I always get the error in IE.
My code is as follows:
iframe id='ifFacebookRego' style='margin-top: 50px' src='https://www.facebook.com/plugins/registration.php?
client_id=******&
redirect_uri=******?method=facebook&fields=[
{ "name":"name" },
{ "name":"first_name" },
{ "name":"last_name" },
{ "name":"email" },
{ "name":"nrl_team", "description":"NRL Team Interest", "type": "select", "options":{ "1":"Broncos",
"2":"Bulldogs",
"8":"Cowboys",
"11":"Dragons",
"9":"Eels",
"7":"Knights",
"10":"Panthers",
"12":"Rabbitohs",
"3": "Raiders",
"13": "Roosters",
"5":"Sea Eagles",
"4":"Sharks",
"6":"Storm",
"16":"Titans",
"15":"West Tigers",
"14":"Warriors",
"17":"Gold Coast Jnr.",
"18":"St. George Jnr.",
"19":"Parramatta Jnr.",
"20":"South Sydney Jnr.",
"21":"Manly Warringah Jnr.",
"22":"Canterbury-Banksrtown Jnr." } },
{ "name":"phone", "description":"Australian Mobile", "type":"text" },
{ "name":"cbHealthNutrition", "description": "Health Nutrition", "type":"checkbox" },
{ "name":"cbEntertainingSolutions", "description": "Entertaining Solutions", "type":"checkbox" },
{ "name":"cbEverydayIdeas", "description": "Easy Everyday Ideas", "type":"checkbox" },
{ "name":"cbHealthForFamily", "description": "Health for my Family", "type":"checkbox" },
{ "name":"gender" }]'
scrolling="auto"
frameborder="no"
style="border:none"
allowTransparency="true"
width="360"
height="650">
/iframe>
Any help would be appreciated.
Thanks.
Found the solution to this issue. Because the fields json is parse in to the iframe in the source url, the url was too long. I shortened the names of my fields and all works.