How to display image using onenote api? - php

I am using onenote api for get the Notebook, section and pages.
I have retrieved the page content using onenote api. But Images are displaying broken link.
I got this error message when i try to retrieve the image using onenote api.
OData Feature not implemented.
Please advise how to solve this issue.
Thanks
Prabhu

If the recalled page's content contains images, the html response will include img tags with src atttribute containing the uri of the resource, for example: https://www.onenote.com/api/v1.0/resources/{id}/$value. You can then make a separate GET request to these endpoints to retrieve the binary contents of the images. Images won't render directly in a browser because they are private and require authorization to retrieve them (like the rest of the page content).
Could you make sure you are attempting to do a GET on a uri of the form I mentioned above. If you still hit errors, please provide the exact uri you are calling and the X-CorrelationId response header value.
Thanks

yes I make a separate GET request to retrieve the binary contents of the images
$url="https://www.onenote.com/api/v1.0/resources/0-5974b01690234c2a9dddd4ed2b59c36f!1-750AB09386EE9836!117/$value";
Response :
HTTP/1.1 501 Not Implemented
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; odata.metadata=minimal
Expires: -1
Server: Microsoft-IIS/8.5
X-CorrelationId: 70069bfa-3fe2-4433-9a43-b7a6a09c8170
X-UserSessionId: 70069bfa-3fe2-4433-9a43-b7a6a09c8170
X-OfficeFE: OneNoteServiceFrontEnd_IN_2
X-OfficeVersion: 16.0.4028.1559
X-OfficeCluster: wus-www.onenote.com
P3P: CP="CAO DSP COR ADMa DEV CONi TELi CUR PSA PSD TAI IVDi OUR SAMi BUS DEM NAV STA UNI COM INT PHY ONL FIN PUR"
X-Content-Type-Options: nosniff
Set-Cookie: s_id=70069bfa-3fe2-4433-9a43-b7a6a09c8170; expires=Thu, 30-Apr-2015 04:33:12 GMT; path=/; secure; HttpOnly
Request-Processing-Time: 15.6314 ms
OData-Version: 4.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 30 Apr 2015 04:33:11 GMT
Content-Length: 149
{
"error":{
"code":"20111","message":"OData Feature not implemented. {0}.","#api.url":"http://go.microsoft.com/fwlink/?LinkID=400828"
}
}

Related

Why Woocommerce API GET request returns an empty cart items list

I have a problem with the API_TEST of my woocommerce site. I am currently building an e-commerce app that uses woocommerce as its backend. I edited a webhook file(class-wc-rest-webhooks-controller.php.) in my Cpanel to enable the "add to cart" functionality. (See file code here: https://github.com/Kings-Samuel/Kings-Samuel/blob/main/class-wc-rest-webhooks-controller.php.php )
Now, to do an HTTP test on PostMan, the POST request works very fine. The GET request works pretty well too but has one problem.
If I update the cart from my woocommerce website, it will return the cart items properly. But if I try to GET the cart items when I use the POST request to update the cart, it will show me a 200 (Success) but refuses to show me the cart items. It just returns an empty cart list.
So, in essence, the GET request works only if the cart was updated from the website. It doesn't work when the cart is updated from the post request or from the app.
Please what could be the problem? Below is the HHTP and JSON detail of what is returned...
HTTP/1.1 200 OK
keep-alive: timeout=5, max=100
content-type: application/json; charset=UTF-8
x-robots-tag: noindex
link: <https://jumbocheap.com/wp-json/>; rel="https://api.w.org/"
x-content-type-options: nosniff
access-control-expose-headers: X-WP-Total, X-WP-TotalPages, Link
access-control-allow-headers: Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Type
allow: GET
vary: Origin,Accept-Encoding
cache-control: public, max-age=0
expires: Sat, 27 Nov 2021 19:00:50 GMT
content-length: 25
date: Sat, 27 Nov 2021 19:00:50 GMT
server: LiteSpeed
x-turbo-charged-by: LiteSpeed
connection: close
{
"status": true,
"data": []
}
I've got the solution to this. It turned out that I once used the lower case to declare a variable instead of a lower camel case in the class-wc-rest-webhooks-controller.php file.
Now, my cart works just fine

Retrieving api's response in json format

I am using the campaign monitor's api and trying to retrieve the response in a json format, which it is supposed to do. I echoed the response, here's an example :
string(342) "HTTP/1.1 400 Bad Request
Server: csw
Cache-Control: private, s-maxage=0
X-CS-Node: 25
Content-Type: application/json; charset=utf-8
P3P: CP="OTI DSP COR CUR IVD CONi OTPi OUR IND UNI STA PRE"
Date: Sun, 27 Jan 2013 12:35:10 GMT
Connection: close
Content-Length: 66
{"Code":250,"Message":"List title must be unique within a client"}"
I would like to get the only last line. How can I do that ? (I tried to explode the response with a white space, but it didn't change anything).
Edit : the documentation is here, I call a method method(), that returns the response $response = method() and I run echo($response)
You could use the preg_match function to search for the JSON by searching for the Regular Expression '/{.*}/'.
preg_match('/\{.*\}/', $response, $matches);
Based on this example code you should be doing:
$result = method(); # I'm assuming you over-simplified the code in your question and "method" isn't the real method name
echo $result->response; # Not echo $result;

How to get Content-Length or CRC in header of a web page?

I wrote a crawler for spesific dynamic website. All crawl jobs taking over 3 hours.
I want to control the page is already crawled or there are some changes on page.
If i can do this the script will be completed in very short time.
for example:
foreach ($urls as $url) {
if(thereAreChanges($url)){
crawl($url);
}
}
Information: The web page doesn't provide content-length and crc.
Array ( [0] => HTTP/1.1 200 OK
[Date] => Tue, 08 Jan 2013 07:47:03 GMT
[Server] => Apache
[Set-Cookie] => Array (
[0] => PHPSESSID=eisb6qjme9b0ouoga9su9fgok4; path=/
[1] => j12011=a%3A3%3A%7Bs%3A3%3A%22sid%22%3Bs%3A26%3A%22eisb6qjme9b0ouoga9su9fgok4%22%3Bs%3A2%3A%22ip%22%3Bs%3A12%3A%2294.103.47.65%22%3Bs%3A4%3A%22time%22%3Bi%3A1357631223%3B%7D; expires=Sat, 09-Mar-2013 07:47:03 GMT; path=/
)
[Expires] => Thu, 19 Nov 1981 08:52:00 GMT
[Cache-Control] => no-store, no-cache, must-revalidate, post-check=0, pre-check=0
[Pragma] => no-cache
[Vary] => Accept-Encoding
[Connection] => close
[Content-Type] => text/html
)
The site provides Content-Type but doesnt provide Content-Length. How can i ask content-length to apache.
Update : http://urivalet.com/ can get content-length. I need this.
If i can get CRC code of page in header. It will be perfect. But I guess this is long shot.
In the function thereAreChanges($url) You can do the following,
When send a request send If-modified-since header with the last time you visit the page as parameter. This header will return 304 status code if its not modified.
Check the Last-Modified header of the response and compare with your current stored page's last modified date. If the content is newer fetch it.
If possible perform HEAD request with those headers. GET will give you all the content. But HEAD will just return headers. For such query only headers are needed.
4.
Its better to use existing crawler and search engine framework than writing one.
Use Apaches Nutch to crawl webpages, Solr to search the indexed pages. Solr provides a HTTP interface where you can run query by PHP. For more flexibility you can use Lucene.
Here is a tutorial on how to setup Nutch and Solr.
Solution is 'header'=>"Accept-Encoding: gzip"
That's why header doesn't return Content-Length, with this parameter page returns content-length.

Smarty IE9 requests file download of index.php (after an upload has not occured)? is it my code at fault or activecollab?

Okay so I'm getting this weird unexpected response from Internet Explorer, while testing file upload with smarty in php.
Here my smarty code for file upload (view), simplified down to main issue, for those who have not used activecollab the Router::assemble is just forming a url with parameters that are read from the MVC.
(source: iforce.co.nz)
<div id="xero_invoice_manager_api">
{form action=Router::assemble('xero_invoice_manager_api') method=post id="xero_invoice_manager" enctype="multipart/form-data"}
<div class="content_stack_wrapper">
<input type="file" name="file_1" /><br/>
<input type="file" name="file_2" /><br/>
{wrap_buttons}
{submit success_event="api_updated" }Authenticate{/submit}
{/wrap_buttons}
{/form}
</div></div>
And here is my jquery for the view.
App.Wireframe.Events.bind('api_event_finished.content', function(event, settings) {
App.Wireframe.Flash.success(App.lang('Xero Invoice Manager has saved/uploaded your Xero API data.'));
});
Here is my simplified controller (I have found the issue is with smarty and not php).
//api view
function api(){
if ( $this->request->isSubmitted()) {
$this->response->respondWithData(true);
}
}
Here is my controller with the upload occuring..
//api view
function api(){
$this->assignSmarty();
if ($this->request->isSubmitted()) {
$this->XeroAuthUpdate(); //update everything
if(isset($_FILES)){
$file_manager = new XeroFileManager();
$file_manager->dumpFiles($_FILES);
//upload the files
foreach($_FILES as $file){
$file_manager->handle_certificate_file($file);
} //foreach add the headers
if(function_exists('headers_list')){
xeroDebugMode("[Controller] the headers to be sent are... ", headers_list());
} //function check
} //end if
$this->response->respondWithData(array(
// constraints
'key_result' => (bool)$this->checkValue(XeroAuths::getSetting('xero_consumer')),
'secret_result' => (bool)$this->checkValue(XeroAuths::getSetting('xero_secret')),
// files secruity certificates
'publickey' => (bool)file_exists(XERO_PUBLIC_KEY_PATH),
'privatekey' => (bool)file_exists(XERO_PRIVATE_KEY_PATH),
'xero_auth' => (bool)validateXeroAuth(),
//login constraints
'install' => !$this->checkInstallRequirements(),
));
} //close the request
}
Here is a response from firefox with the file_1 and file_2 not empty.
(source: iforce.co.nz)
Here is a response from internet explorer 9 with file_1 and file_2 empty (so far so good).
(source: iforce.co.nz)
Here is the problematic response from internet explorer 9 with file_1 (i.e. publickey.cer) and file_2 (i.e. privatekey.pem) not empty (download index.php huh?).
(source: iforce.co.nz)
My response from activecollab
Hello Micheal,
Sorry for the late reply.
Unfortunately we cannot figure out where the problem is. It looks like everything is written OK but without dealing with the code itself there's pretty much nothing we can do. Dealing with JSON responses in IE works fine across activeCollab (well, not in IE6) since almost everything in aC 3 is based on JSON, which makes your issue specific and probably there's something wrong in your code.
Regards,
Oliver Maksimovic
activeCollab development & support
General and Pre-Sale Questions: 1-888-422-6260 (toll-free) Technical Support: support#activecollab.com
An associate has suggested..
Would suggest trying the following though:
1) open IE -> open the developer tools (press F12) -> Click "Cache" in menu -> click "Clear Browser Cache"... When thats finished click "Cache" and then click "Always refresh from server".
this forces IE to not cache anything, as I've had numerous times where IE was caching ajax requests and causing some very strange behaviour.
let me if this fixes your problem, and if so we can add some php to your ajax response to force all browsers to never cache the response. otherwise if that still doesn't work, probably need to do some JS debugging in IE, to see what's being sent and compare it to your FF firebug results.
headers_sent() comes up blank
but the headers_list (just before respondWithData is called), for Internet Explorer.
2012-08-08 06:50:16 the headers sent from this request is... Array
(
[0] => X-Powered-By: PHP/5.3.8
[1] => Set-Cookie: ac_activeCollab_sid_yhRk0xSZku=1%2Fhkykz0Rw0796e4lDykXekNXvhMMxC8pV4akJPMvA%2F2012-08-08+06%3A50%3A15; expires=Wed, 22-Aug-2012 06:50:15 GMT; path=/
[2] => Content-Type: application/json
[3] => Expires: Mon, 26 Jul 1997 05:00:00 GMT
[4] => Cache-Control: no-cache, no-store, must-revalidate
[5] => Pragma: no-cache
)
Response Headers from Raw tab on Fiddler, on Internet Explorer
HTTP/1.1 200 OK
Date: Sat, 11 Aug 2012 08:08:46 GMT
Server: Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.8
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: ac_activeCollab_sid_yhRk0xSZku=11%2Fz8rWxiRchAh8EWinYO2d7a1mmvn2DMKUdse1vfKh%2F2012-08-11+0 8%3A08%3A46; expires=Sat, 25-Aug-2012 08:08:46 GMT; path=/
Content-Length: 107
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
{"key_result":true,"secret_result":true,"publickey":true,"privatekey":true,"xero_auth":true,"install":true}
Response Headers from Raw tab on Firefox.
HTTP/1.1 200 OK
Date: Sat, 11 Aug 2012 08:13:45 GMT
Server: Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.8
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: ac_activeCollab_sid_yhRk0xSZku=12%2FO40CbXC9Vfa7OVnderlK2MFnvnpkyeckvO0Ab5NQ%2F2012-08-11+08%3A13%3A45; expires=Sat, 25-Aug-2012 08:13:45 GMT; path=/
Content-Length: 107
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
{"key_result":true,"secret_result":true,"publickey":true,"privatekey":true,"xero_auth":true,"install":true}
Any ideas on what I'm doing wrong with IE? and why Internet Explorer is notifying the user to download index.php (when the fields are active with values). Keeping in mind that no actual uploading is occurring on the server-side (during the initial test, the index.php download request is irrelevant to move_uploaded_file).
It could be that IE specific code has an error, and so the returned content-type is different. If you make an AJAX request for some kind of XML or JSON data and instead get some kind of file HTML error response with a different content-type or disposition than expected, the browser might not know what to do with it.
You might want to find a way to view or log the response (as opposed to request) headers sent by the web server. Usually a prompt for file download comes from a content-disposition header... though in this case it might just be because it's a file coming from an asynchronous request.
You might also want to look at:
IE prompts to open or save json result from server
and
How can I convince IE to simply display application/json rather than offer to download it?
I had a similar issue using pupload and mvc3. I know we use different technology but maybe my issue could help you. I had this:
public JsonResult UploadDoc(string correlationId)
{
try
{
//upload code here
return Json(new { message = "chunk uploaded", name = "test" });
}
catch (Exception ex)
{
return Json(new { message = "chunk uploaded", name = "test" });
}
}
Now everytime I wanted to try upload a file I would get IE asking me to open or download a file which just contained that json response above. If I set my return type as "String" and set my return code as:
return "{\"respCode\" : \"200\", \"Msg\" : \"succussful\",\"mimeType\": \"" + Request.Files[0].ContentType + "\", \"fileSize\": \"" + Request.Files[0].ContentLength + "\"}";
Then the file was successfully uploaded. Response Header for when it failed: "Content-Type: application/json; charset=utf-8" . Response Header for when it works with "String" return type:
"Content-Type: text/html; charset=utf-8". Hope it helps, cheers.
Due to the lack of answers, I think I need to take a different approach in my jquery.. until an actual solution is found.

Extracting the response body from http_post_data in PHP

I am using PHP http_post_data() call to send data to a cakephp controller.I do it like this:
$response=http_post_data($url, $xml_data_encoded);
The data arrives ok to the destination and I get a response which holds the response status.In my case the status is number 1 which means -data delivered ok.As you can see from the code below I get not only the status number (which is at the bottom of the message) but also the whole http post header.How can I strip this message off the header code so that eventually the response message holds only the status number?
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Thu, 10 Nov 2011 08:34:15 GMT
Server: Apache/2.2.17 (Ubuntu)
X-Powered-By: PHP/5.3.5-1ubuntu7.3
Set-Cookie: CAKEPHP=xxxxxxxxxxxxxxxx; expires=Fri, 18-Nov-2011 16:34:15 GMT; path=/XXXXXXXXXX/xxxxxxxx
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Vary: Accept-Encoding
Content-Length: 19
Content-Type: text/html
1
Btw, I also tried this:
HttpMessage::getBody(http_post_data($url, $xml_data_encoded));
and got no response at all.
Any help will be highly appreciated.
$response = http_post_data($url, $data);
preg_match_all('~HTTP/1\.[01]\s(\d{3})~', $response, $codes);
$codes would store all matches. Just print_r the array and look for desired keys.
Instead of a regular expression you can use http_parse_message
$response = http_parse_message(http_post_data($url, $data));
print $response->body;

Categories