MS ToDo API is giving error for few users in Taskfolders Endpoint - outlook-restapi

MS ToDo API is giving error for few users when using following endpoint :
https://outlook.office.com/api/v2.0/me/taskfolders
Here is the piece of code :
$accessToken = "eyJ0eXAiOiJKV1QiLCJub25jZSI6I*******sYVg0X0";
$url = "https://outlook.office.com/api/v2.0/me/taskfolders";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => array('Authorization: Bearer '.$accessToken)
));
$output=curl_exec($ch);
Here is the error which I am getting :
stdClass Object (
[error] => stdClass Object
(
[code] => ErrorItemNotFound
[message] => The specified object was not found in the store.
)
)
As per the documentation of MS, we should get the list of default folder.
Here is the MS documentation link
That means, I should get default folder list in response and which I am getting in case of other users.
I checked the token validity, it is alive.
Any help is appreciated and thank you in advance.

In case if you're talking about shared tasks then it's not supported at this point. I remember an user voice on this - https://microsoftgraph.uservoice.com/forums/920506-microsoft-graph-feature-requests/suggestions/40295248-get-shared-task-folders-using-graph-api. You may want to vote for it, so that Microsoft can consider for it

Related

Generate Authorization token for MuleSoft API in NetSuite

I am trying to call Mulesoft API endpoint from NetSuite user event script. I need to generate token to send it with API call.
Question:
should i create schedule script to generate the token and store it somewhere?
how often the token should be refreshed?
Postman token generation is working fine. I would love to know how should I setup this in NetSuite.
Postman:
Apologies in advance as I cannot comment, low Rep.
I haven't worked with Mulesoft or Oauth2, I mostly work on Oauth1.
According to your comments, it expires in 4 Hours. I suggest you store the generated Access Token in Script Parameter. NetSuite Script Parameter. You can call task.create to schedule a script to refresh the Access Token every 4 hours as stated on the notes on this page Referencing Script Parameters
EDIT: Had to confirm few things regarding Script Parameter. According to some articles, Script Parameter are global and can be called from different scripts (has to be set as company preference when creating parameter). So, scheduled script and storing it to a parameter and having your UE Script fetching the value of that parameter will work.
Adding this code sample to #Nukedd's answer.
Here's an example of storing/fetching access token in Cache.
const CACHE_NAME = 'MY_CACHE';
const ACCESS_TOKEN = 'MY_ACCESS_TOKEN';
const cache = require('N/cache');
// Storing access token to server cache
const storeAccesstoken = () => {
var myCache = cache.getCache({
name: CACHE_NAME,
scope: cache.Scope.PRIVATE
});
myCache.put({
key: ACCESS_TOKEN,
value: '12345accesstoken',
ttl: 14400
});
}
// Fetching access token from server cache
const getAccessToken = () => {
const myCache = cache.getCache({
name: CACHE_NAME
});
const myAccessToken = zipCache.get({
key: ACCESS_TOKEN,
loader: loaderFunction
});
return myAccessToken;
}
Please see the following:
N/cache Module
cache.Scope
Note: This is only supported by server scripts.

Does Instagram Reels have an API for developers?

I cannot find an Instagram Reels related API. Does anyone know if there is one or if there will be one?
Currently the Facebook developer documentation does not mention anything about Instagram Reels.
https://developers.facebook.com/docs/instagram-api/overview/
UPDATED ANSWER:
Reels are now supported via the API; it became generally available on July 6, 2022. Please see https://developers.facebook.com/blog/post/2022/06/27/introducing-reels-apis-to-instagram-platform/.
ORIGINAL ANSWER:
In the Instagram API docs, under Limitations, it currently says "Reels are not supported."
Reels it is IG Media with type "VIDEO".
And you can fetch single "Reels" if you know his Facebook Media ID (It is not Media ID from instagram)
If reels published like stories you can get media's list from stories endpoint(GET graph.facebook.com/{ig-user-id}/stories). You will get array of medias' ids.
"data": [
{
"id": "{ig-media-id}"
},
...
]
}
Then you can fetch information from single media object endpoint (GET /{ig-media-id})
So at current moment you can get reels by api only if they published like story.
Anyway reels is not supported in some countries and you can see reels only from stories in this countries.
UPDATE
Reels also available when you fetch user media from business-discovery(GET {ig-user-id}?fields=business_discovery.username(instagramm_user_name){media{id,permalink,media_type,media_url}}
) or user media (GET /{ig-user-id}/media).
If media's permalink look likes https://www.instagram.com/reel/... and media_type VIDEO then is it reels.
Not sure, but I did some digging around an Instagram .ipa file and found these url scheme parameters.
instagram://reels_home
instagram://reels_share
Both of which if clicked on ios will take you to the reels feed. My intentions are to open the reels camera (or the story camera with the mode set to reels), but i guess currently we can only access the reels feed.
It seems they were included in the GET /{ig-user-id}/media and the GET {ig-user-id}?fields=business_discovery.username(instagramm_user_name) endpoints at the beginning but they removed them later. According to the docs they are not supported at the moment. Further confirmed in this bug report. It seems it is not the first time they include nodes that are not supposed to be included (IGTV and now reels).
Naa,
Instagram doesn't provide any API for Reels yet, since the reel feature is still not available in many countries but this going to be available soon.
So the question arises here, how we can get the reels data via API?
Well, the answer is you can't But! if you are in favour to do so some scraping thing then the answer is definitely Yes!
But How?
We all know scraping has lots of efforts, due to things get changed very frequent. and if you don't care about those below are sample PHP script to fetch reels data in JSON.
<?php
//!IMPORTANT
$sessionid = ["Cookie: sessionid=YOUR SESSION ID HERE"];
// REELS SHORT CODE FROM URL
$shortcode = null;
$response = [];
/**
* Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an
* array containing the HTTP server response header fields and content.
*/
function get_web_page($url)
{
$user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
$options = array(
CURLOPT_CUSTOMREQUEST => "GET", //set request type post or get
CURLOPT_POST => false, //set to GET
CURLOPT_USERAGENT => $user_agent, //set user agent
# CURLOPT_COOKIEFILE => "cookie.txt", //set cookie file
# CURLOPT_COOKIEJAR => "cookie.txt", //set cookie jar
CURLOPT_HTTPHEADER => $sessionid, // sending manually set cookie
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
$header = curl_getinfo($ch);
curl_close($ch);
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
if ((isset($_GET['q'])) && !empty($_GET['q'])) {
$shortcode = $_GET['q'];
$reels_url = "https://www.instagram.com/p/$shortcode/?__a=1";
// read a web page and check for errors:
$result = get_web_page($reels_url);
if ($result['errno'] != 0) {
$response = json_encode(['error' => "bad url, timeout, redirect loop"]);
}
if ($result['http_code'] != 200) {
$response = json_encode(['error' => "no page, no permissions, no service"]);
}
if ($result['http_code'] === 200) {
$response = $result['content'];
}
}
// JSON OUTPUT OR ERROR HERE
header('Content-Type: application/json');
echo $response;
How to use this PHP script?
Save the above script in a PHP file e.g. fetch-reels.php and run it like
http://localhost/fetch-reels.php?q={SHORT-CODE}
Reels URL e.g.
https://www.instagram.com/p/COlKxQLAM11
https://www.instagram.com/reel/COlKxQLAM11/?igshid=12f6j9a1dfx2x
As mentioned earlier Instagram doesn't provide direct apis but you can take help of Instagrapi its really awesome and easy to use. Note : This Instagram Private API wrapper is in python.
Here's how to use it -
Install the lib :
python -m pip install instagrapi
Code
from instagrapi import Client
cl = Client()
#enter your username and password
cl.login('username', 'password')
#you can replace 10 with whatever amount of reels you want to fetch
reel = cl.explore_reels(amount = 10)
print(reel)
That's it !!!
Instagram just released reels support (Available to everyone from July 7th 2022).
More here
https://developers.facebook.com/docs/instagram-api/guides/content-publishing/
Instagram Reels API is now generally available:
https://developers.facebook.com/blog/post/2022/06/27/introducing-reels-apis-to-instagram-platform/
You can make a scheduled post. For example using JavaScript and uploading a video to the Reels API[1]:
const access_token = "Js82ks92jald"; // The access token given from FB
const instagram_user_id = "12345"; // The IG user's ID
const reelUrl = "https://www.website.com/reel.mp4";
const caption = "This is the best real ever #Reels4Real";
const postUrl = `https://graph.facebook.com/${instagram_user_id}/media?video_url=${encodeURIComponent(reelUrl)}&caption=${encodeURIComponent(caption)}&access_token=${access_token}&media_type=REELS&share_to_feed=true&thumb_offset=2000`;
const postOptions = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
};
fetch(postUrl, postOptions)
.then((res) => res.json())
.then(json => console.log(json))
.catch(console.error);
Note the key fields of media_type=REELS, video_url, and caption.
[1] https://www.ayrshare.com/instagram-reels-api-how-to-post-videos-to-reels-using-a-social-media-api/
Update (14-July-2022): Meta (Facebook) launched support for Reels via their official Graph API. Read more about it here: https://developers.facebook.com/docs/instagram-api/reference/ig-user/media#reel-specifications
Meta just release Reels API for the Instagram Platform.
https://developers.facebook.com/blog/post/2022/06/27/introducing-reels-apis-to-instagram-platform/

nodejs googlephotos fails to upload with "Authentication session is not defined"

I've got some code based on the samples given at the googlephotos documentation. I basically just took the code provided as-is and modified it to fill in my client id, secrets, etc. generate a URL which I then paste into my brower, and after clicking through to authorize my app I copy the code it gives me and using it to construct a new Photos object.
I tried setting up my scopes as:
const scopes = [
Photos.Scopes.READ_ONLY,
Photos.Scopes.SHARING,
Photos.Scopes.APPEND_ONLY
];
But I also tried:
const scopes = [
Photos.Scopes.APPEND_ONLY
];
and
const scopes = [
Photos.Scopes.READ_AND_APPEND
];
I am able to to get back auth tokens which I can use to build a new Photos object. I try to upload something like this:
const response = await photos.mediaItems.upload("", "test.mp4", "/home/michael/test/test.mp4", "Test Upload");
I get this error along with a stack trace which seems useless:
(node:13122) UnhandledPromiseRejectionWarning: StatusCodeError: 401 - "{\n \"code\": 16,\n \"message\": \"Authentication session is not defined.\"\n}"
I have granted append permission, which is all that should be for this to have the proper authorization, yet it still fails! What am I doing wrong here?
The documentation isn't super-specific about exactly what "auth_token" you are supposed to pass, merely saying:
const photos = new Photos(your_google_auth_token);
without defining what your_google_auth_token is or where it comes from. Google's own documentation for the upload API just says oauth2-token which isn't helpful in getting to the bottom of what this value should be.
In the same code for getting the tokens it just says:
const {tokens} = await oauth2Client.getToken(code)
// The token from above can be used to initialize the photos library.
This error occurs when you naively plug the tokens you get into the constructor like so:
const photos = new Photos(auth_token)
Instead, what you need to do is plug the access_token field of the tokens like this:
const photos = new Photos(auth_token.access_token)

Impossible to get an access_token for Instagram Basic Display API

I'm trying to get an access_token from Instagram to use their Basic Display API for a new app (simply display tweets on a webpage).
I followed these steps: https://developers.facebook.com/docs/instagram-basic-display-api/getting-started
But I'm stuck at Step 5: Exchange the Code for a Token
The cURL request always returns a 400 error with the message: "Matching code was not found or was already used"
However, after many tests, I got an access_token one time only, but it expired about one hour later. This seems to be very random.
The Instagram Basic Display API seems rather new. A while ago, I have used apps created on the https://www.instagram.com/developer/ website and it used to work. Now this site display this message:
UPDATE: Starting October 15, 2019, new client registration and permission review on Instagram API platform are discontinued in favor of the Instagram Basic Display API.
... with a link to the developers.facebook.com.
I tried using the command-line tool as per the original docs(https://developers.facebook.com/docs/instagram-basic-display-api/getting-started), but no luck...
Here's what to do in 3 easy steps:
First thing: Install Postman https://www.postman.com/downloads/
Make a POST request to https://api.instagram.com/oauth/access_token with the parameters in the body, NOT the params. Make sure that the x-www-form-urlencoded option is enable.
You should now get a status of 200 OK and a response with both access_token and user_id.
{
"access_token": "IGQVJYUXlDN...",
"user_id": 17841400...
}
Happy days!!
See the screenshot for the correct settings:
I just succeeded by removing the trailing #_ at the end in the code they give you. Not sure if that was your issue?
https://developers.facebook.com/support/bugs/436837360282557/
I had this problem when i was trying implement a application.
My problem was the code generated when you allow the permissions.
Try to remove #_ from the end of the generated code and try generate the token again
Generated code example:
AQBvrqqBJJTM49U1qTQWRMD96oRyMR3B_04JSfjc-nUIi0iGbSc3x_EceggQi9IyG3B3Rj3ocreMThQoPJbPpeXLUM4exJMy4o01fXcRtT_I9NovaNAqmWSneFt3MYv_k7ifAUUeMlC050n5xnjQP6oAvDBfCFQvTdrFaR95-5i71YsfQlmjYWDG6fcWRvOB9nqr6J9mbGMXMi9Y4tKlSfElaYm0YKRijZQDG2B5PaxQ8A #_
Generated code edited:
AQBvrqqBJJTM49U1qTQWRMD96oRyMR3B_04JSfjc-nUIi0iGbSc3x_EceggQi9IyG3B3Rj3ocreMThQoPJbPpeXLUM4exJMy4o01fXcRtT_I9NovaNAqmWSneFt3MYv_k7ifAUUeMlC050n5xnjQP6oAvDBfCFQvTdrFaR95-5i71YsfQlmjYWDG6fcWRvOB9nqr6J9mbGMXMi9Y4tKlSfElaYm0YKRijZQDG2B5PaxQ8A
I was also having the same problem, I solved clearing the cache, coockie and other browser data.
Then I made a new request.
Try it, it worked with me.
I found the solution.
The direct uri must the same as you use in the beginning.
ex. You use
www.abc.com/auth
to get the code. When you exchange the token the redirect_uri must be the same as
www.abc.com/auth
I was using the old Instagram API as well. I had to change a few things to make my code work on the new API. Not sure what you're using, this is how I did it with PHP.
$url = 'https://api.instagram.com/oauth/access_token';
$fields = array(
'app_id' => 'YOUR_APP_ID',
'app_secret' => 'YOUR_APP_SECRET_ID',
'grant_type' => 'authorization_code',
'redirect_uri' => 'YOUR_REDIRECT_URL',
'code' => $code
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
//get the access token from the string sent from Instagram
$splitString = explode('"access_token":', $result);
$removeRest = explode(',', $splitString[1]);
$withSpace = str_replace('"','', $removeRest[0]);
$access_token = str_replace(' ','', $withSpace);
I am using PHP but without using any lib. Maybe this one help you.
curl.php
class InstagramApi
{
public function GetAccessToken($client_id, $redirect_uri, $client_secret, $code) {
$url = 'https://api.instagram.com/oauth/access_token';
$curlPost = 'app_id='. $client_id . '&redirect_uri=' . $redirect_uri . '&app_secret=' . $client_secret . '&code='. $code . '&grant_type=authorization_code';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = json_decode(curl_exec($ch), true);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($http_code != '200')
throw new Exception('Error : Failed to receieve access token');
return $data;
}
index.php
include "curl.php";
include "instagram_keys.php"; // holding APP ID, SECRET KEY, REDIRECT URI
$instagram_ob = new InstagramApi();
$insta_data = $instagram_ob->GetAccessToken(INSTAGRAM_CLIENT_ID, INSTAGRAM_REDIRECT_URI, INSTAGRAM_CLIENT_SECRET, $_GET['code']);
echo $insta_data['access_token'];
echo $insta_data['user_id'];
NOTE: $_GET['code'] is required and you should know how to get the code. Read here

How to solve fatal error when not receiving data and it sends data when loading the page again stripe?

When I send the data of the card to make the purchase by means of stripe it shows me the following message:
Successfully charged $50!
tok_1BKYfLDi3J7CIS2eVqZVeZqT
But when you do not receive data when sending the payment data shows these errors
Notice: Undefined index: token in C:\xampp\htdocs\DesignFormStripe\charge.php on line 9
Fatal error: Uncaught Stripe\Error\Card: Cannot charge a customer that has no active card in C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiRequestor.php:128 from API request 'req_W6Qbd7iMVHDsGS' Stack trace: #0 C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiRequestor.php(102): Stripe\ApiRequestor::_specificAPIError('{\n "error": {\n...', 402, Array, Array, Array) #1 C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiRequestor.php(309): Stripe\ApiRequestor->handleErrorResponse('{\n "error": {\n...', 402, Array, Array) #2 C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiRequestor.php(65): Stripe\ApiRequestor->_interpretResponse('{\n "error": {\n...', 402, Array) #3 C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiResource.php(119): Stripe\ApiRequestor->request('post', '/v1/charges', Array, Array) #4 C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiResource.php(158): Stripe\ApiResource::_staticRequest('post', '/v1/charges', Array, NULL) #5 C:\xampp\htdocs\DesignFormStripe\php\lib\str in C:\xampp\htdocs\DesignFormStripe\php\lib\stripe\lib\ApiRequestor.php on line 128
How can I fix those running errors?
Update my question
Fix previous errors with the documentation of Stripe, on handling errors.
The code is almost solved in the following way:
<?php
require_once('./config.php');
$token = $_POST['token']; // retrieve token POST parameter to charge the card (stripeToken)
$customer = \Stripe\Customer::create(array(
'email' => 'customer2#example.com',
//'email' => $_POST['stripeEmail'],
'card' => $token
));
try {
// Use Stripe's library to make requests...
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => 500,
'description' => 'Event charge',
'currency' => 'usd'
));
echo '<h1>Successfully charged $50!</h1>';
echo "$token";
} catch(\Stripe\Error\Card $e) {
// Since it's a decline, \Stripe\Error\Card will be caught
$body = $e->getJsonBody();
$err = $body['error'];
print('Status is:' . $e->getHttpStatus() . "\n");
print('Type is:' . $err['type'] . "\n");
print('Code is:' . $err['code'] . "\n");
// param is '' in this case
print('Param is:' . $err['param'] . "\n");
print('Message is:' . $err['message'] . "\n");
} catch (\Stripe\Error\RateLimit $e) {
// Too many requests made to the API too quickly
} catch (\Stripe\Error\InvalidRequest $e) {
// Invalid parameters were supplied to Stripe's API
} catch (\Stripe\Error\Authentication $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
} catch (\Stripe\Error\ApiConnection $e) {
// Network communication with Stripe failed
} catch (\Stripe\Error\Base $e) {
// Display a very generic error to the user, and maybe send
// yourself an email
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
}
?>
Now when opening the page without received data it shows the following message:
Status is:402 Type is:card_error Code is:missing Param is:card Message is:Cannot charge a customer that has no active card
Now a new problem :(
But when loading the page again, and confirm form re-submission, it shows the same messages of previous errors.
I imagine that the error is shown because Stripe only accepts the Token generated at the request of the charge only once.
But instead of showing these errors when confirm form re-submission, show an custom error message, for example: The payment request is already in process.
The issue here is that your code expects the card token tok_XXXX to be present in $_POST['token']. It seems that there are cases where the parameter is not sent by your form when the form is submitted though and you're not catching it.
Because of this, $token is empty and simply not sent to Stripe and the customer is created without a card. The next step is to charge the customer but since it has no card the API returns an error.
You need to change two things in your code to avoid this. First off, you should make sure that you catch all errors that can be returned by Stripe's API as documented here. The idea is that you catch the exception and then you display a user-friendly error message while you log the detailed error on your end to solve this.
Then, you need to add some logic at the beginning of your code that will ensure that $_POST['token'] is set as expected. If not, leave early and return an error to the customer.
Finally, the issue usually comes from a bug client-side where your form can be submitted without the token being created successfully first. Common issues come from not disabling form submission until a token is created or not properly initializing JS code on some browsers.

Resources