LinkedIn: Creating a company share for a photo - linkedin-api

I'm suffering to create a company photo share on Linkedin.
I've seen several threads, where people say, they could create a photo share on LinkedIn by creating a link share, passing the image URL for the "submitted-url".
E.G. Consider the following payload:
```
{
"visibility": { "code": "anyone" },
"content": {
"submitted-url": "localhost/image.jpg"
}
}
```
In my case, at least, the share appears as a link share on LinkedIn. I've also tried the combinations of providing the "title" etc. fields, but no luck.
Next, I've found the following documentation: https://developer.linkedin.com/docs/guide/v2/shares/rich-media-shares#upload
That does not seem to be linked from the https://developer.linkedin.com/docs, so I have no clue if this documentation still applies.
I've tried the following endpoint: "https://api.linkedin.com/media/upload" with the "Content-Type: application/x-www-form-urlencoded" and "Authorization: Bearer ..." -headers, with file payload but the response is:
```
{
"serviceErrorCode": 100,
"message": "Not enough permissions to access media resource",
"status": 403
}
``
It does not matter, what permissions I have set for my app.
I happen to know from some applications, there is a way to share photo shares on LinkedIn via the API, but I don't manage to find the correct documentation where this is described.
If you know a way that worked for you but isn't already listed here, please inform me and all the others suffering from this problem :)
And if someone from LinkedIn could add the proper documentation, that would be superb!
Thanks!

Meanwhile, our application got accepted to LinkedIn "marketing partner" program which gives you access to LinkedIn API V2, the documentation is publicly available, but you need to manually apply for it. They may or may not accept your application.
Just couple gotchas for the next person who may struggle with this or some other issues we encountered.
Once our application got accepted to the "marketing partner"-program, we started to receive strange errors for our LinkedIn v1 API calls, namely "410 Gone" - "This resource is no longer available under v1 APIs".
All the calls using the application that got the permissions to API v2 were failing to this error. There was no way to use the old API with that application any longer.
The email confirming our application's acceptance to the program was sent to us in one day delay from when these problems started. Strange way to deal API switch, but luckily we have access to API v2 now.
LinkedIn API v2 gives you the possibility to upload and publish photo shares (one or many photos), which isn't possible with API v1.
The error we received for every call to API v1 after the acceptance:
{
"status": 410,
"message": "This resource is no longer available under v1 APIs",
"errorCode": 0,
"requestId": "removed",
"timestamp": 1522333590761
}

LinkedIn provides rich media API to do an image share.
Lets assume you already have an access token (access_token), your organization id is org_id and the image file name is "flower.png"
1) Below call helps you to upload the image to LinkedIn using upload media API
curl -X POST \
https://api.linkedin.com/media/upload \
-H 'authorization: Bearer <access_token>’ \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F fileupload=#flower.png
The above call returns the below response format:
{
"location": “<image_urn>“
}
2) Now using the above image_urn in response, you will be able to create an image share using the below call
Please replace access_token, org_id and image_urn with the original values before making the below call
curl -X POST \
https://api.linkedin.com/v2/shares \
-H 'authorization: Bearer <access_token>’ \
-H 'content-type: application/json' \
-d '{ "owner": "urn:li:company:<org_id>“,
"text": {
"text": "test image attachemnt 0614"
},
"subject": "test image attachemnt 0614",
"distribution": {
"linkedInDistributionTarget": {}
},
"content":{
"contentEntities": [
{
"entity": “<image_urn>”
}
],
"description": "content description1",
"title": "Test Share with Image"
}
}'

Related

Facebook graph api page post with multiple photos

I am trying to publish a page post with multiple photos via the Facebook's graph api.
Currently from the docs and another question here it's stated that the photos should be uploaded separately and then publish the post with attached_media parameter.
The photos are uploaded fine without any problem and I get their IDs.
The issue is that the request for publishing the post gives:
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1,
"fbtrace_id": "SOME TRACE ID"
}
If I remove the attached_media parameter from the request the post is published fine.. Any Idea what can be the issue?
Specially for CBroe here are the reqiests:
For the photo upload:
endpoint: /{page-id}/photos
payload:
{
"url": "some-image-url",
"caption": "Some image caption",
"published": false
}
endpoint: /{page-id}/feed
payload:
{
"message": "Some post message",
"published": false,
"attached_media": [
{"media_fbid": "PHOTO_ID_RETURNED_FROM_THE_ABOVE_REQUEST"}
]
}
The payload is send as json to the endpoint. This request works only if I remove the attached_media parameter.
TL;DR
Add publish_to_groups permission to the access token and the request for the post should be with parameter published: true. It appears to have a bug in the graph api or lack of information in the official docs.
Details:
Currently in order to publish a page post with multiple photos you will need to:
upload individually the photos and obtain their IDs
use PAGE access token which contains publish_to_groups permission
attach all photo IDs with attached_media[0..N]: {"media_fbid": "PHOTO_ID"}
currently the request for publishing the post fails if it's with parameter published: false, so it needs to be published: true
All of this does not make really sense to me, so I opened a bug report in the developers platform of Facebook. It does not looks right during development of the App to publish live posts to the page...
I'll edit the answer once I have a feedback.

Facebook API error subcode 33

I have an app that gets leads from facebook after webhook request when leads fill out forms: Some pages are throwing this error:
{
"error": {
"message": "Unsupported get request. Object with ID '233332620530416' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "HIItB4mggfk"
},
"__debug__": {}
}
I cannot find the error subcode description in Facebooks API docs.
Check you access token at https://developers.facebook.com/tools/debug/accesstoken
Your app might be missing a needed permission scope.
Visit Business Settings > Users > System Users > Chose «Conversions API System User» > Add Assets. Add your Pixel with ID from your request to the list of assets System User can access.
I have had this issue a few times and the error led me to spend an hour or two combing the docs. The real issue for me each time has been malformed json in the request body (I'm using curl). Dumb I know, but in case a poor soul comes across this. Be sure to validate your json before you decide you query is wrong.
I got this error when adding access_token in post body, worked when adding parameters to url.
Success result using postman
Not success result using postman
Add your access token in the Authorization tab, then choose Oauth2.0 and add your access token on the right side. Please refer to the screenshot for the postman.Click here for the screenshot
I found the answer recently
Follow this steps using postman
https://graph.facebook.com/page-name/feed
headers:
Content-Type: application/x-www-form-urlencoded
Body:
message: "your message"
link:"your web link "
access_token:'Your access token '

Form designer for Facebook Messenger apps?

I'm a veteran programmer, however I am new to the Facebook Messenger API. I have seen that the API does support buttons as per this code snippet from the Facebook developers web site that uses a CURL example to demonstrate the formatting code:
https://developers.facebook.com/docs/messenger-platform/send-api-reference/button-template
curl -X POST -H "Content-Type: application/json" -d '{
"recipient":{
"id":"USER_ID"
},
"message":{
"attachment":{
"type":"template",
"payload":{
"template_type":"button",
"text":"What do you want to do next?",
"buttons":[
{
"type":"web_url",
"url":"https://petersapparel.parseapp.com",
"title":"Show Website"
},
{
"type":"postback",
"title":"Start Chatting",
"payload":"USER_DEFINED_PAYLOAD"
}
]
}
}
}
}' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"
This looks like typical JSON to me. Is there a GUI tool that can design these layout elements, not only for buttons, but for any other Facebook Messenger form template elements that may also exist in the API? Something that uses a drag and drop or other GUI interface that then generates the necessary JSON code or fragment to represent the designed form?
If so, please leave its name or a link to it.
There is the Platform Design Kit for Sketch: https://developers.facebook.com/docs/messenger-platform/design-resources/design-kit

Facebook and Parse: Code 251, Error: Parse::InvalidSessionError

I'm trying to set up a chrome extension that uses a Facebook Access token to login to Parse using the JS api. As a proof of concept I tried following the example here with curl, but when I put in my access_token and expiration_date, the POST call returns {"code":251,"error":"Parse::InvalidSessionError"}
Specifically, I'm calling this from the OSX shell.
curl -X POST
-H "X-Parse-Application-Id: [my app id]" \
-H "X-Parse-REST-API-Key: [my rest api key]" \
-H "X-Parse-Revocable-Session: 1" \
-H "Content-Type: application/json" \
-d '{
"authData": {
"facebook": {
"id": "[my id as a string]",
"access_token": "[my token as a string]",
"expiration_date": "2015-10-26T07:45:16.579Z"
}
}
}' \
https://api.parse.com/1/users
I've googled around a bit, including reading the following posts, but after changing my settings on my Facebook app multiple times and re-authenticating, it is still throwing the same error.
Using FB user to login on parse. Error code: 251, Invalid Sesion Error
Parse Facebook login fails with error code 251
For the record, I've tried changing my "App Secret embedded in the client" Facebook setting to false, as well as my "Native or desktop app?" to both yes and no (I'm fairly sure it should be set to yes, as I'm using the desktop app FB login flow.) I've also added my facebook app to my parse app, and enabled Facebook integration on parse, as well as double checking my parse app and rest api keys.
Please let me know what else I should try, or what other information you need to assess this.
Two things were wrong with the way I was approaching this.
I was creating the "Expires_at" field by adding the "Expires_in" field (returned using this FB login flow) to the current time as calculated by my browser. In retrospect this was silly, as the expiration time is supposed to be exact, and network latency will change the calculated time by a bit.
I was using the wrong facebook ID for my request - there are two types of IDs now, and you need to use the correct one. See this link..

Facebook Ads API - How to create NewsFeed ads?

I can successfully create right column ads, but failed to create NewsFeed ads.
According to what I know, I should create type 27 creative first, and for this purpose, I need to provide parameter object_id and story_id. The first one is our company's facebook page, and the 2nd one is an unpublished post on that page.
To create a story, I used the codes below. I think it should be 'promotable_posts'. This is to create an unpublished post in the page so that it can be used in the newsfeed ad.
$api.put_connections('id_of_companys_fb_page', 'promotable_posts',
{
"message" => 'my_message',
"name" => "my_name",
"link" => "url_of_a_page",
"caption" => "my_caption",
"description" => "This is a longer description",
"picture" => "url_to_a_picture"
}
Unfortunately it always throws exception "type: GraphMethodException, code: 100, message: Unsupported post request. [HTTP 400] (Koala::Facebook::ClientError)".
If I change 'promotable_posts' to 'feed', then it works, but I cannot use the post id to create the ad, and I noticed that the id starts with 5xxx.. which is different from other manually created posts ids (starting with 1xx..) that worked. I even tried other types, but none works. I didn't find an example to create such post.
Any suggestions, even wild-guess, are appreciated.
Are you using the Ads API documentation?
Once you create the page post (via the /feed connection of the page) or have someone create it using the page management interface you create a type 25 or 27 ad using the post ID you retrieve from the API, or from the response of the API call you used to create the post itself.
The /promotable_posts endpoint returns the ID of any posts that can be turned into ads, it's a subset of the posts on /posts
A sample type 25 and 27 ad creative are included in the 'examples' section of the Creative Specs documentation
e.g. the type 27 example, modified to use a specific post ID, not the most recent post on the page:
curl \
-F "name=sample creative" \
-F "type=27" \
-F "object_id=<PAGE ID>" \
-F "story_id= <POST ID>" \
-F "access_token=_____" \
"https://graph.facebook.com/act_<ACCOUNT ID>/adcreatives"