Facebook api returns : (#120) Invalid album id when trying to post to a group - api

When I try to post a photo in a group through the API I get an error, the post happens, but without the photo.
I've seen people say it's a bug on Facebook and it happens when there's a question mark (?).
However in my post there is no question mark, does anyone know what it could be?
The error i get is: (#120) Invalid album id
Example:
I am using Facebook SDK for PHP like this, and i have a custom method, like this.
public function postPhoto(string $message, string $img_path, string $page, string $id='me')
{
$photoData = [
'message' => $message,
'source' => $this->fb->fileToUpload($img_path),
];
$this->pageAccessToken = $this->getTokenForPage($page);
try {
$response = $this->fb->post("/$id/photos", $photoData, $this->pageAccessToken);
$graphNode = $response->getGraphNode();
$this->post_id = $graphNode['id'];
} catch (FacebookResponseException $e) {
$this->error = $e->getMessage();
return false;
} catch (FacebookSDKException $e) {
$this->error = $e->getMessage();
return false;
}
}

Related

xero api failing to add tracking on purchase order

When I add tracking to invoices or credit notes via the api it works fine. but when i try to add it on purchase order it fails and I cannot seem to get a clear error message out of it.
I am using accounting api https://xeroapi.github.io/xero-php-oauth2/docs/v2/accounting/index.html#api-Accounting-updatePurchaseOrder
Error I get is message: "[400] Client error: POST https://api.xero.com/api.xro/2.0/PurchaseOrders/42797164-58c9-483c-9af8-96165c31a26f` resulted in a 400 Bad Request response:\n{\r\n "ErrorNumber": 10,\r\n "Type": "ValidationException",\r\n "Message": "A validation exception occurred",\r\n "Elements" (truncated...)\n"
`
Code I am using to try set it after I have created the purchase order.
[$trackingCategoryId, $trackingOptionId] = $this->getTrackingCategoryByNameFromXero($projectName, 'Project');
$purchaseOrder = null;
$xeroTenantId = $this->xero_account->tenantId;
try {
$purchaseOrders = $this->accountingApi->getPurchaseOrder($xeroTenantId, $purchaseOrderId);
foreach ($purchaseOrders as $model) {
if ($model->getPurchaseOrderId() == $purchaseOrderId) {
$purchaseOrder = $model;
break;
}
}
} catch (Exception $e) {
echo 'Exception when calling AccountingApi->getPurchaseOrder: ', $e->getMessage(), PHP_EOL;
}
if ($purchaseOrder instanceof PurchaseOrder) {
$lineItems = $purchaseOrder->getLineItems();
foreach ($lineItems as $lineItem) {
$tc = new LineItemTracking();
$tc->setTrackingCategoryId($trackingCategoryId);
$tc->setTrackingOptionId($trackingOptionId);
$lineItem->setTracking([$tc]);
$lineItems[] = $lineItem;
}
$purchaseOrder->setLineItems($lineItems);
$purchaseOrders = new PurchaseOrders();
$arr_purchase_orders[] = $purchaseOrder;
$purchaseOrders->setPurchaseOrders($arr_purchase_orders);
$summarizeErrors = true;
try {
$x = $this->accountingApi->updatePurchaseOrder(
$this->xero_account->tenantId,
$purchaseOrderId,
$purchaseOrders
);
} catch (\ApiException $e) {
print_r($e->getMessage());die;
}
}

Flutter : How to delete Rest Api Using Http.Client?

I develope App for CRUD Operation rest api using Http Client. GET and POST work perfectly, but problem come after DELETE Operation.
Console Message show me response code Bad Request 400 **, I Check code rest Api (in my codeigniter) **Bad Request 400 it's means the ID is null or not passing the ID on URL Rest Api.
It's Console Message Image
But I try on POSTMAN and **DELETE* is perfectly work , i dont know why in flutter http.delete not working.
It's Result POSTMAN Working
My Api Url for Delete
http://192.168.43.159/wpu-rest-server/apii/mahasiswa/delete/
It's My API.dart :
Future<bool> checkPost(Map<String, dynamic> id) async {
final client = http.Client();
try {
final response = await client.send(http.Request(
"DELETE", Uri.parse("${Urls.BASE_API_URL}mahasiswa/delete/"))
..headers['Content-type']= 'application/x-www-form-urlencoded'
..body = jsonEncode(id));
print(response.reasonPhrase);
print(response.statusCode.toString());
print(response.request.toString());
return response.statusCode == 204;
} finally {}
}
It's My list.dart :
void _checkPost() async{
final post = {"id":widget.id};
bool result = await api.checkPost(post);
if (result) {
_showSnackBar(
context, 'Success ');
} else {
_showSnackBar(context, 'Failed');
return null;
}
}
If you need Rest Api Code :
Controller
public function delete_delete()
{
$id = $this->delete('id');
$msgDelete = ['id' => $id, 'message' => 'Deleted the resource'];
$msgEmpty = ['status' => false, 'message' => 'ID Not Found'];
$msgBadRequest = ['status' => false, 'message' => 'Provide an ID'];
if ($id === null) {
$this->set_response($msgBadRequest, 400);
} else {
if ($this->mahasiswa->deleteMahasiswa($id) > 0) {
$this->set_response($msgDelete, 204);
} else {
$this->set_response($msgEmpty, 404);
}
}
}
Model
public function deleteMahasiswa($id = null)
{
if ($id === null) {
return false;
} else {
$this->db->delete('mahasiswa', ['id' => $id]);
return $this->db->affected_rows();
}
}
I'm mistake something ?
I ever heard httpclient.delete can't add body , but in POSTMAN need add body for deleting data, how to handle this ?

Gmail API get list "An error occurred: { "error": "invalid_grant", "error_description": "Bad Request" } " in PHP

I am trying to get mail list using php library. It was working before , but now it show the following error :
An error occurred: { "error": "invalid_grant", "error_description":
"Bad Request" }
array(0) { }
Code:
function getList($lastsynctime='') {
// Get the API client and construct the service object.
$client = $this->getClient();
$service = new Google_Service_Gmail($client);
// $newTime = strtotime('-15 minutes');
if ($lastsynctime =='') {
$newTime = strtotime('-60 day');
$after = strtotime(date('Y-m-d H:i:s', $newTime));
}else{
$after = strtotime($lastsynctime);
}
// Print the labels in the user's account.
$userId = 'me';
$pageToken = NULL;
$messages = array();
$opt_param = array();
do {
try {
if ($pageToken) {
$opt_param['pageToken'] = $pageToken;
}
$opt_param['q'] = "from:example#gmail.com after:$after";
$messagesResponse = $service->users_messages->listUsersMessages($userId, $opt_param);
echo "<pre>";var_dump($messagesResponse);
} catch (Exception $e) {
print 'An error occurred: ' . $e->getMessage();
}
} while ($pageToken);
return $messagesResponse;
}
Well! As your code was working before and you haven't change anything. Then i think the problem is not in you code.
You can check your Connected apps and sites settings under your gmail My Account menu to make sure your app is there.
If the app is there but yet not working then you need to delete the app and regenerate your client secret key. Because your client secret may get expired.
I got this error in different API (Google Search Console).
Try visiting https://myaccount.google.com/security#connectedapps from your Gmail account.
See if Drive Testing Key shows up under Apps with account access. If it doesn't, then as #Mahbubul Islam mentioned, you'll need to create the credentials again.

modify relationship in instagram by using oriceon laravel 5 oauth wrapper

Iam using oriceon/oauth-5-laravel for connecting with instagram.I authenticated and i got my name and id by through this request
$result = json_decode($instagramService->request('users/self'), true);
Now i want to follow a person by using this oriceon/oauth-5-laravel.
How i could post the request to follow a person by using this .
**NOTE:**dont refer the instagram developer page.I reffred it a lot.But i couldnt put a post request for ORICEON/laravel oauth wrapper for instagram.
HELP ME.TYSM in advance
try this .Copy this method to your controller and do proper routing.
public function followWithInstagram(Request $request)
{
$instagram_id='id of the user that you want to follow';
$code = $request->get('code');
$instagramService = \OAuth::consumer('Instagram');
if ( ! is_null($code))
{
$state = isset($_GET['state']) ? $_GET['state'] : null;
$instagramService->requestAccessToken($code, $state);
$linkData = [
'action' =>'follow',
];
$result =json_decode($instagramService->request('https://api.instagram.com/v1/users/'.$instagram_id.'/relationship','POST',$linkData),true);
if(!$result){
return ("Failed");
}
else {
return ("SUCCESS");
}
} else {
$url = $instagramService->getAuthorizationUri();
return redirect((string)$url);
}
}

Vimeo API to fetch video with vanity url?

Does anybody know how to get a response from Vimeo's api for vanity / custom urls like the following:
http://vimeo.com/jarominne/regarde-moi or http://vimeo.com/davidfield/caterpillar
The standard Api request for a video id doesn't work.
Does not work: https://vimeo.com/api/v2/video/regarde-moi.json
Works: https://vimeo.com/api/v2/video/58086788.json
I don't see anything that makes sense or is a clear cut solution in their docs. I don't care about language.
FWIW, this is a crappy php solution I just quickly thought of shortly after asking this question.
Improvements very welcome!
Essentially, if we do not have a video id (a numeric value), assume our id is a video title. Fetch our user data with the username from the url and grab all their videos. Loop through those videos and try and match the title with our "video id" (which in the case above is really the video title).
** assumes $this->id = your video id or video username
** assumes $this->user = your vimeo username
public $apis = array(
'vimeo_image' => 'http://vimeo.com/api/v2/video/%s.json',
'vimeo_user' => 'http://vimeo.com/api/v2/user/%s/videos.json'
);
public function vimeoThumbnail($size = 'small')
{
if(preg_match('/[0-9]+/', $this->id)) {
$video_id = $this->id;
} else {
$videos = file_get_contents(sprintf($this->apis['vimeo_user'], $this->video->user));
if($videos !== false) {
$videos = json_decode($videos);
foreach($videos as $video) {
if(stristr($video->title, $this->id)) {
$video_id = $video->id;
break;
}
}
}
}
$contents = file_get_contents(sprintf($this->apis['vimeo_image'], $video_id));
if($contents !== false) {
$contents = json_decode($contents);
if(is_array($contents)) $contents = array_shift($contents);
if(!is_object($contents)) return false;
$image_url = $contents->{'thumbnail_' . $size};
return $image_url;
}
return false;
}