LinkedIn API to post Share using php oauth class - php

The details:
I am using Manuel Lemos php oauth class and the login_with_linkedin.php script as reference.
I have successfully gone through the oauth process and retrieved the user's info using the API 'http://api.linkedin.com/v1/people/~'
I get an error when using the Post Shares API (http://api.linkedin.com/v1/people/~/shares)
Here is the relevent code from my last unsuccessful attempt;
// Scope settings
$client->scope = 'r_fullprofile r_emailaddress r_network rw_nus';
// Call to API (Post)
$success = $client->CallAPI(
'http://api.linkedin.com/v1/people/~/shares',
'POST', array(
"format"=>"json",
"comment"=> "Test"
), array('FailOnAccessError'=>true), $user);
Here is the error message:
Error: it was not possible to access the API call: it was returned an unexpected response status 401 Response: { "errorCode": 0, "message": "Unknown authentication scheme", "requestId": "8DWA0EBJTB", "status": 401, "timestamp": 1355774186502 }
Any help would be greatly appreciated. Thank you.

I posted the same issue on the class creator's forum as well.
He got back to me with an answer that worked.
The answer can be found here:
http://www.phpclasses.org/discuss/package/7700/thread/22/

Related

Making with Microsoft Graph an OnlineMeeting object error 403

Im doing and application with PHP, which use Microsoft Graph API. Actually i couldnt found any documentation for php, so im follow microsoft tutorial.
So first i tried to do the microsoft page example for post method:
POST https://graph.microsoft.com/beta/app/onlineMeetings
Content-Type: application/json
Content-Length: 1553
{
"meetingType": "meetNow",
"participants": {
"organizer": {
"identity": {
"user": {
"id": <id user azuread teenant>
}
}
}
},
"subject": "subject-value"
}
actually it doesnt work on microsoft graph explorer. I already gave all permissions and ir returns the following:
Failure - Status Code 403, 440ms Looks like you may not have the permissions for this call.
{
"error": {
"code": "Forbidden",
"message": "",
"innerError": {
"request-id": "fd8cdedd-99f1-4bca-9de6-29a77f834bba",
"date": "2019-04-25T18:06:43"
}
}
}
I though explorer dont work with onlinemeetings and calls, so i stopped to use it, and i tried on a php app.
Then i tried this:
// Create a Graph client
// Set graph version
// Get user info
$graph = new Graph();
$graph->setAccessToken($accessToken);
$graph->setApiVersion("beta");
$createTeamsUrl = '/app/onlineMeetings';
$events = $graph->createRequest('POST', $createTeamsUrl)
->attachBody($body)
->execute();
accessToken is the returned token from oauth v2.0, and it works.
I already gave to my azure ad aaplication all permissions for test purpuoses (including delegated and app such as OnlineMeetings.ReadWrite.All), but this returns the same error.
I did some others request, like this:
//works
$graph = new Graph();
$graph->setAccessToken($accessToken->getToken());
$user = $graph->createRequest('GET', '/me')
->setReturnType(Model\User::class)
->execute();
and this works.
I also downloaded c# sample, and it works, so i think its not permissions
https://github.com/microsoftgraph/microsoft-graph-comms-samples/
If anyone knows if this is supported or not, could be useful.
Thanks.
If you are using common as tenant to get the access token, first thing you have to do is use your tenant id instead of common word, as explained here. This worked for me.
Getting same 403 forbidden error on creating online meeting
also added "OnlineMeetings.ReadWrite.All" permission in the scope

Facebook Graph-api, premissions for Shares count (Invalid OAuth access token signature)

I am far from the programming and PHP, but got the challenge to get the Fb share count for the website :)
I'm trying to get the proper App Access Token and send the request to Fb
according to this article.
The request should be like this:
https://graph.facebook.com/?ids=http://www.myurl.com/my-page&access_token=myappid|myappsecret
And I getting this error.
{
"error": {
"message": "Invalid OAuth access token signature.",
"type": "OAuthException",
"code": 190,
"fbtrace_id": "FfZKAkCyad1"
}
}
I am going to use it in PHP roughly like this:
function facebook_count($url)
{
$results = #file_get_contents('http://graph.facebook.com/' . $url .'&access_token=myappid|myappsecret');
if ($results) {
$like_array = json_decode($results, true);
if (!empty($like_array['shares']))
return ($like_array['shares']);
}
return 0;
}
My guess, I checked wrong Permissions (scopes) for my App token. Did not found an answer in FB dev page. Checked this for now:
user_likes, read_insights, read_audience_network_insights, public_profile
What Scope do I need to check, if I need only the shares count by the link?
Or in what else could be the problem?
You need to use an App Access Token... So the actual permissions (referring to User Access Tokens!) are irrelevant.
So, hopefully you are replacing myappid|myappsecret with your actual App Id and App Secret. If ynot, there's your error. Furthermore, I think in the file_get_contents call then ?id= part in the URL is missing.

APINotAllowedError while getting recent photos from instagram

I am getting the following error while using the media/recent API.
{
"meta": {
"error_type": "APINotAllowedError",
"code": 400,
"error_message": "This tag cannot be viewed"
}
}
I have tried with client Id and access token.
https://api.instagram.com/v1/tags/mytag/media/recent?client_id=clientId
or
https://api.instagram.com/v1/tags/mytag?access_token=accesstokem
Also, I created new App in different Instagram account and tried. It gives me the same error.
Only for particular hashtag I am getting this error, for other hashtags I am getting the proper response.
Please help me.

Facebook Graph API. How to get comment from post

Hi i have this to get comment from post it works is there is a years
$json = file_get_contents("http://graph.facebook.com/730350233684840/comments?limit=2500");
echo $json;
but now i have this error in facebook
{
"error": {
"message": "An access token is required to request this resource.",
"type": "OAuthException",
"code": 104
}
}
how i can get all comment from post ?
i have using your code #luschn
my request with true APP ID and App Secret
https://graph.facebook.com/730350233684840/comments?limit=2500&access_token=[APPIS|APPSECRT]
i have this
{
"error": {
"message": "Invalid OAuth access token signature.",
"type": "OAuthException",
"code": 190
}
}
i use chrome to look this error
--
English is not my native language, sorry for any mistakes.
For example:
$json = file_get_contents("http://graph.facebook.com/730350233684840/comments?limit=2500&access_token=[your-access-token]");
The most basic Access Token is an App Access Token, you can create one like this:
$appAccesstoken = $appId . '|' . $appSecret;
Depending on the resource, you may need a User or Page Token though. For that, you will have to authorize the User and it gets a lot more complicated.
More information about Access Tokens:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
you have to change the position access token and limit
https://graph.facebook.com/167416583311544_730350233684840/comments?access_token=appId|appSecret&limit=2500

Comment Posted but OAuthException Returned

I'm using the official Facebook PHP SDK to interact with the graph API. According to the Facebook documentation here, I'm using the following API method to post a comment to a Facebook wall post:
public function post_comment($id, $comment) {
$publish = $this->facebook->api("/$id/comments", "post", array('message' => $comment));
return $publish;
}
The comment is successfully posted to Facebook: I can see it on Facebook's website after posting it, however the API itself returns:
PHP Fatal error: Uncaught OAuthException: An unexpected error has occurred. Please retry your request later.
Which in turn causes my server to return a 500 internal server error.
Given that the comment successfully posts, I don't see how there can be an OAuth exception?
Any help would be gratefully accepted.
EDIT:
I ran the same methods on Facebook's Graph API explorer, and got the same output. The comment posted fine, but the graph explorer threw the Uncaught OAuthException error, too. I have all the default permissions selected, including publish_stream and publish_actions. The specific output was:
{
"error": {
"message": "An unexpected error has occurred. Please retry your request later.",
"type": "OAuthException",
"code": 2
}
}
Hey here you go with some demo code.
The $POST_ID thingy must be set by you ofc.
try{
$response = $facebook->api("/".$POST_ID."/comments","POST",array (
'message' => 'This is a test comment',
)
);
}catch(FacebookApiException $e){
error_log($e->getMessage());
}

Categories