Magpie RSS / User Authorization - php

How can I get Magpie RSS to identify itself as a user?
HTTP Response: HTTP/1.1 401 Unauthorized
is the error that i'm getting returned

Since you didn't post any code, I assume you're calling MagpieRSS like:
$rss = fetch_rss('http://www.site.com/feed.rss');
To identify as user/password, just change the URL to this format:
$rss = fetch_rss('http://username:password#www.site.com/feed.rss');
See PHP's parse_url for more info.

Related

how to validate RSS feed URL in simplpie library

I want to validate RSS feed URL before its process for parsing. I am using willvincent/feeds library for this.
$feed = Feeds::make($rssurl);
$items = $feed->get_items();
I am parsing RSS feed like above.
So how can validate the RSS feed URL before parsing using willvincent/feeds library.
'willvincent/feeds' is just a service provider for Laravel.
You should refer to SimplePie documentation, and use the error() method to check if url throws errors. This method holds the error description.
$feed = Feeds::make('http://some-bogus-feed-url');
if($feed->error()){
//handle the feed error
}

Parsing JSON in PHP is not giving response

So I am trying to get some information from a JSON file. But for some reason there is no actual response with the information that I need.
This is the code im running.
$json_object = file_get_contents('http://steamcommunity.com/profiles/'.$steamID.'/inventory/json/730/2');
$json_decoded = json_decode($json_object);
echo $json_decoded->success;
I get the steamID from a cookie. But if you want to see how the JSON looks, then you can check out this link:
http://steamcommunity.com/profiles/76561198031313244/inventory/json/730/2
The problem is that the URL you are checking is redirected to another URL, file_get_contents() doesn't support following redirects AFAIK, so you should better use cURL
Check this answer https://stackoverflow.com/a/4324018/5658508
the problem is like the others tell you is in this link http://steamcommunity.com/profiles/76561198031313244/inventory/json/730/2
i just monitor the response, so when you visit the link you get a 302 Moved Temporarily http response to the new link which is http://steamcommunity.com/id/SANDISS/inventory/json/730/2
you can try to get contents using file_get_contents if you have the link not just a steam id, or use curl library

How to do a composite search in bing search API?

I'm trying to do a composite search in bing search API using php. From this documentation i got this.
https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=%27web%2bnews%27&Query=%27XBox%27&$top=1 This gives some result which i don't know to parse and show the result. I tried `simplexml_load_file()` to parse but no use.
If i mention json format request like below i get a bad request sent error( failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request) and file_get_contents() error
https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=%27web%2bnews%27&?$format=json&Query=%27XBox%27&$top=1
How to get the result with json?
Correct query for you is: (I removed "?" before $format=json)
https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=%27web%2bnews%27&$format=json&Query=%27XBox%27&$top=1

Linkedin flag as job - php

I'm trying to flag post-id as job discussion with OAuth PUT :
$post_id = "G-34343-example";
$cmd = "http://api.linkedin.com/v1/posts/{$post_id}/category/code";
$xml = "<?xml version='1.0' encoding='UTF-8'?><code>job</code>";
$this->oauthc->fetch($cmd, $xml, OAUTH_HTTP_METHOD_PUT, array("Content-Type" => "application/xml"));
But I'm getting an error:
Someone know what does it mean?
com.linkedin.common.leo.core.UnauthorizedActionException: Unauthorized change of forum type
The problem lies here:
<?php
$post id = "G-34343-example";
?>
There's a space in the variable name. Use an underscore instead of a whitespace to make it work.
(This: $cmd = "http://api.linkedin.com/v1/posts/{$post_id}/category/code"; will contain a blank spot where the post id should be.)
Is the user you are connecting with using the API authorized to flag posts in the target group? Have you tried logging in to LinkedIn directly as this user, going to the target forum and attempted to flag a post?
When creating a group post, it's URL is returned in the "location" header. For some reason, the URL from the location header is using http and not https.
If you're using OAuth2, LinkedIn returns a 401 if you try to access the API with http instead of htttps. So if you're getting a 401 response, check that you're using https.
So the code should be something like:
$url = $response->headers['location'] . '/category/code';
$url = str_replace('http://', 'https://', $post_url);
// ...

PHP simplexml_load_file catch 403

I am using the following PHP:
$xml = simplexml_load_file($request_url) or die("url not loading");
I use:
$status = $xml->Response->Status->code;
To check the status of the response. 200 bening everything is ok, carry on.
However if I get a 403 access denied error, how do I catch this in PHP so I can return a user friendly warning?
To retrieve the HTTP response code from a call to simplexml_load_file(), the only way I know is to use PHP's little known $http_response_header. This variable is automagically created as an array containing each response header separately, everytime you make a HTTP request through the HTTP wrapper. In other words, everytime you use simplexml_load_file() or file_get_contents() with a URL that starts with "http://"
You can inspect its content with a print_r() such as
$xml = #simplexml_load_file($request_url);
print_r($http_response_header);
In your case, though, you might want to retrieve the XML separately with file_get_contents() then, test whether you got a 4xx response, then if not, pass the body to simplexml_load_string(). For instance:
$response = #file_get_contents($request_url);
if (preg_match('#^HTTP/... 4..#', $http_response_header[0]))
{
// received a 4xx response
}
$xml = simplexml_load_string($response);
You'll have to use something like the cURL module or the HTTP module to fetch the file, then use the functionality provided by them to detect an HTTP error, then pass the string from them into simplexml_load_string.

Categories