shareable link of messanger using facebook graph api - php

I am using a Facebook graph to fetch comments on particular posts. The response is something like this
{
"data": [
{
"message": "43211234",
"created_time": "2021-01-09T05:33:14+0000",
"from": {
"name": "USER NAME",
"id": "USER ID"
},
"id": "COMMENT ID"
}
],
"paging": {
"cursors": {
"before": "M...",
"after": "M.."
},
"next": "https://graph.facebook.com/v9.0/10...."
}
}
the response looks good, but I also want a shareable messenger link of the user who has commented so that I can talk to that person later. is there any solution for this? I searched for it but could not find any solution.

Related

LinkedIn API UGC post success but not showing?

I believe I am successfully posting a new post to the endpoint
https://api.linkedin.com/v2/ugcPosts
using (similar to)
{
"author": "urn:li:organization:1234567",
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"attributes": [],
"text": "Some share text"
}
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
The response I get is
{"id":"urn:li:share:01234567890123456789"}
But then when I go to the company page, the post is not visible. Note that the IDs are redacted here. Is there another step I have to take?
edit: I went to verify the post with the endpoint https://api.linkedin.com/v2/ugcPosts/[redacted URN]?viewContext=AUTHOR and my post is a success
{
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"inferredLocale": "en_US",
"attributes": [],
"text": "Test article sharing article on LinkedIn API , please ignore"
},
"media": [
{
"media": "urn:li:digitalmediaAsset:XXXXXXXXXXXXXX",
"title": {
"attributes": [],
"text": "image"
},
"thumbnails": [],
"status": "READY"
}
],
"shareFeatures": {
"hashtags": []
},
"shareMediaCategory": "IMAGE"
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
},
"created": {
"actor": "urn:li:person:XXXXXXXXXXXXXX",
"time": 1649285262053
},
"author": "urn:li:organization:XXXXXXXXXXXXXX",
"clientApplication": "urn:li:developerApplication:XXXXXXXXXXXXXX",
"versionTag": "0",
"id": "urn:li:share:XXXXXXXXXXXXXX",
"firstPublishedAt": 1649285262053,
"lastModified": {
"actor": "urn:li:csUser:7",
"time": 1649285262122
},
"distribution": {
"externalDistributionChannels": [],
"distributedViaFollowFeed": true,
"feedDistribution": "MAIN_FEED"
},
"contentCertificationRecord": "{\"spamRestriction\":{\"classifications\":[],\"contentQualityClassifications\":[],\"systemName\":\"MACHINE_SYNC\",\"lowQuality\":false,\"contentClassificationTrackingId\":\"073BB82AD64A7608E3F142B6D0362E3D\",\"contentRelevanceClassifications\":[],\"spam\":false},\"originCountryCode\":\"ca\",\"modifiedAt\":1649285262024,\"contentHash\":{\"extractedContentMd5Hash\":\"0725A7E31B109EB4CFB84D2648CE3EC8\",\"lastModifiedAt\":1649285262023}}"
}
What am I missing here?? Why is it now showing on LinkedIn??
edit2 : went ahead and tried to share the post again, now all the posts are gone from the company page when viewed as admin, but showing (except the API posts) as a member.... How broken is this API ??????
I will answer my own post. Uploads using CurlFile DO NOT WORK, you have to use Guzzle... Once the upload & publishing are done, the feed will unbreak itself.. The company page will be broken if the endpoint is still waiting for upload while you post.
$client = new \GuzzleHttp\Client();
$res = $client->request('PUT', $__url, [
'headers' => [
'Authorization' => 'Bearer ' . $__token
],
'body' => fopen($__file, 'r')
]
);
if($res){
$res = json_decode($res->getBody());
}

How to get an email address and other info like name and phone together after getting access token LinkedIn signup API with PHP

I am able to gent email using https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~)) and able to get name and profile pic using https://api.linkedin.com/v2/me.My question is that how can i get it together.Is there any single API to call and get all profile info together?
The documentation says something about lite and basic profile permissions but unfortunately there doesn't seem to be a way to get both in one query.
Profile Json Response:
{
"firstName":{
"localized":{
"en_US":"Bob"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"localizedFirstName": "Bob",
"headline":{
"localized":{
"en_US":"API Enthusiast at LinkedIn"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"localizedHeadline": "API Enthusiast at LinkedIn",
"vanityName": "bsmith",
"id":"yrZCpj2Z12",
"lastName":{
"localized":{
"en_US":"Smith"
},
"preferredLocale":{
"country":"US",
"language":"en"
}
},
"localizedLastName": "Smith",
"profilePicture": {
"displayImage": "urn:li:digitalmediaAsset:C4D00AAAAbBCDEFGhiJ"
}
}
Contact Json Response:
{
"elements": [
{
"handle": "urn:li:emailAddress:3775708763",
"handle~": {
"emailAddress": "ding_wei_stub#example.com"
},
"primary": true,
"type": "EMAIL"
},
{
"handle": "urn:li:phoneNumber:6146249836070047744",
"handle~": {
"phoneNumber": {
"number": "158****1473"
}
},
"primary": true,
"type": "PHONE"
}
]
}
The reason might be that there are separated APIs, Contact API and Profile API.

"URL Can't Be Used" error in adding facebook post with child_attachments via api

i'm trying to make a post on facebook using api with using child_attachments param, so i can pass multiple urls in 1 post.
In facebook debugger i'm passing json like that
{
"message": "test debug",
"child_attachments": [
{
"link": {
"link": "https://google.com"
}
},
{
"link": {
"link": "https://ft.com"
}
}
]
}
but i'm getting following error message
{ "error": {
"message": "Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_data": {
"blame_field_specs": [
[
"child_attachments[0][link]"
]
]
},
"error_subcode": 2061006,
"is_transient": false,
"error_user_title": "URL Can't Be Used",
"error_user_msg": "The URL you entered, \"https://google.com\" doesn't direct to a website. Please enter a valid URL and try again.",
"fbtrace_id": "xxxxxxxx"
}
}
i've tried setting urls in app domains , i tried use urls with / without https and with/without www.
still no luck, can some one give me some advise?
Thanks,
Roman.
ok, so i figured, the correct format should be like that:
{
"message": "message to post",
"link": "https://yahoo.com",
"child_attachments": [
{
"link": "https://yahoo.com",
"name": "name -1",
"picture": "https://images.all-free-download.com/images/graphiclarge/ethereal_image_185195.jpg"
},
{
"link": "https://google.com",
"name": "name - 2 ",
"picture": "https://images.all-free-download.com/images/graphiclarge/ethereal_image_185195.jpg"
}
]
}
note that even despite of the thing you adding links in the child_attachments, you must provide 'link' parameter also for post

Get instagram user analytics by username

I want to get the instagram user analytics, i. e. to get the time sheet with count of followers and followings.
Is there any way to get the data from instagram api?
Or Is there other sites that I can get the analytics automatically with PHP?
No analytics API from Instagram yet. we have to search users by user id.
https://www.instagram.com/developer/endpoints/users/#get_users
In the api response the user json contains "counts" for followers, following and medias.
If you just has usernames with you then first search the users from user name by https://www.instagram.com/developer/endpoints/users/#get_users_search; get ids from them and use above API.
To generate the trend; we have to make the API calls daily, for all users!
very costly, but there is no direct API available from Insta yet.
However, FB just released new API for user insights under graph api.
https://developers.facebook.com/docs/instagram-api/reference/user#insights
this works only for instagram business accounts though. and you need the access tokens on behalf of the account you want insights for.
As of 2019-06 you can only access analytics (they call it insights at FB) for your own profile. You can't access insights of other user profile.
For example, let's get your own followers_count.
graph.facebook.com
/{your_facebookPage_id}/insights?metric=followers_count&period=day
You get this JSON as response:
{
"insights": {
"data": [
{
"name": "follower_count",
"period": "day",
"values": [
{
"value": 2,
"end_time": "2019-06-24T07:00:00+0000"
},
{
"value": 0,
"end_time": "2019-06-25T07:00:00+0000"
}
],
"title": "Follower Count",
"description": "Total number of unique accounts following this profile",
"id": "{your_facebookPage_id}/insights/follower_count/day"
}
],
"paging": {
"previous": "https://graph.facebook.com/v3.3/{your_facebookPage_id}/insights?access_token=...&pretty=0&metric=follower_count&period=day&since=1561115213&until=1561288013",
"next": "https://graph.facebook.com/v3.3/{your_facebookPage_id}/insights?access_token=...&pretty=0&metric=follower_count&period=day&since=1561460815&until=1561633615"
}
},
"id": "{your_facebookPage_id}"
}
I used this API
https://graph.facebook.com/v3.2/{ig-user-id}?fields=business_discovery.username(ig-username){followers_count,media_count,media{comments_count,like_count}}&access_token={access-token}
Of course, it does not provide full analytics, but you can get a lot of information about users through username. And response will be:
{
"business_discovery": {
"followers_count": 267793,
"media_count": 1205,
"media": {
"data": [
{
"comments_count": 50,
"like_count": 5841,
"id": "17858843269216389"
},
{
"comments_count": 11,
"like_count": 2998,
"id": "17894036119131554"
},
{
"comments_count": 28,
"like_count": 3644,
"id": "17894449363137701"
},
{
"comments_count": 43,
"like_count": 4943,
"id": "17844278716241265"
},
{
"comments_count": 60,
"like_count": 9347,
"id": "17899363132086521"
},
{
"comments_count": 63,
"like_count": 6913,
"id": "17893114378137541"
},
{
"comments_count": 16,
"like_count": 2791,
"id": "17886057709171561"
},
{
"comments_count": 15,
"like_count": 3895,
"id": "17856337633208377"
},
],
},
"id": "17841401441775531"
},
"id": "17841405976406927"
}

Facebook graph api comments pagination

I'm trying to get all the comments of post by using the following api url request:
$fb->get($yourPage.'/feed?fields=comments.limit(100)&limit=25&since=2017-7-01&until=2017-7-31', $accessToken);
But some posts have more than 500 comments which yields pagination '(next)' in the api response. Now I want to retrieve all the comments, so how do I paginate through the "comments" because I know how to paginate through posts through this code:
$response = $fb->get($yourPage.'/feed?fields=comments.limit(500)&limit=25&since=2017-7-01&until=2017-7-31', $accessToken);
$comments = $response->getGraphEdge();
$totalcomments = array();
if ($fb->next($comments)) {
//Do something if there is pagination in the posts
}
So how do I do the same for comments? I've searched alot on stack and google but no questions point to this... Thanks
Each comments object includes a paging object for that:
{
"comments": {
"data": [
{
"created_time": "2017-09-01T12:06:19+0000",
"from": {
"name": "xxx",
"id": "1234"
},
"message": "xxx",
"id": "1234"
},
...
],
"paging": {
"cursors": {
"before": "NzkZD",
"after": "NzgZD"
},
"next": "https://graph.facebook.com/v2.10/cccccc/comments?access_token=xxx&pretty=0&limit=2&after=NzgZD"
}
},
"id": "xxx"
}
For every post you get, you need a subroutine (for example, with a recursive function) to use the "next" parameter in a separate API call to get all comments.

Categories