Facebook SDK works on PHP 5.2, not on 5.3 - json

I'm having a terrible time of it trying to implement the Facebook PHP SDK on a new server. I'm running the following code:
require('facebook.php');
$facebook = new Facebook(array(
'appId' => "###",
'secret' => "###",
));
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
if ($like_status) {
include('fan.php');
}
else {
include('visitor.php');
}
This all works perfectly under my server running PHP 5.2.17, but breaks under PHP 5.3.3. Both servers have cURL and JSON functioning properly. As far as I can tell, no errors are being thrown, but $facebook->getSignedRequest(); is returning as null.
I'm almost certain that there's something in my server configuration that's bollocksing the whole thing up, but for the life of me I can't figure out what. Any help would be greatly appreciated. Thanks in advance!

I looked into the FB PHP SDK, getSignedRequest method and it used the $_REQUEST superglobal, the PHP manual says that in
5.3.0 - Introduced request_order. This directive affects the contents of
$_REQUEST.
Either the values of $_REQUEST are overwritten somehow. This might be something to look into.

Related

Swift Mailer stopped working after update to PHP 8.1

I recently updated PHP version on our server to 8.1.11, and SwiftMailer stops working. Specifically, this function causes a HTTP 500 error on the page:
$transport = Swift_SmtpTransport::newInstance("smtp.gmail.com", 465, "ssl")
-> setUsername($row["email"])
-> setPassword($row["password"])
;
There's no reason to believe the server or email details are incorrect. It's something to do with the function call itself. A Swift Mailer help article directed me here.
Anyone know what I need to do?

Exception: '<' is an invalid start of a value

I have a Blazor Webassembly project with a controller method as follows:
[HttpGet]
public async Task<List<string>> GetStatesForProfile()
{
IConfigurationSection statesSection = configuration.GetSection("SiteSettings:States");
var sections = statesSection.GetChildren();
var states = statesSection.GetChildren().Select(s => s.Key).ToList<string>();
return states;
}
The razor page calls this method:
private async Task<bool> GetStatesModel()
{
try
{
States = await http.GetJsonAsync<List<string>>("api/account/getstatesforprofile");
...
}
catch (Exception ex)
{
Console.WriteLine($"Exception: {ex.Message}, Inner: {ex.InnerException.Message}");
}
I get this Exception:
Exception: '<' is an invalid start of a value.
I read these values from appsettings.json file, And there is no '<' in values.
{
"SiteSettings": {
"States": {
"New York": ["NYC"],
"California": ["Los Angeles", "San Francisco"]
}
}
Also I put a breakpoint in the controller method and it doesn't hit.
What is this error? Is it from parsing json? and how to resolve this?
I had a very similar problem.
In the end it turned out that my browser had cached the HTML error page (I guess I had some problems with the code when I first tried it). And no matter how I tried fixing the code I still only got the error from cache. Clearing my cache also cleared the problem.
It happens when you're trying to access an API that doesn't exist. You have to check your API project connectionstring under AppSettings and make sure it's correct and running. If it's a Blazor project, you can set it as your default project, execute and see if you get a json response.
Most probably the response you are receiving is html instead of actual JSON format for the endpoint you are requesting. Please check that.
An as HTML usually starts with <html> tag, the JSON validator fails on the very first character.
You should also clear any cache, that might be interfering with the returned data. (this has helped people resolve this same issue)
I know this is an old question, but it's one of the top results when Googling the error.
I've just spent more time than I care to admit to tracking down this error. I had a straightforward Blazor hosted app, basically unchanged from the template. It worked just fine when run locally, but when published to my web host API calls failed. I finally figured out that the problem was that I was running the publish from the Client project. When I changed to the Server project it worked properly.
Hopefully my long frustration and slight stupidity will save someone else making a similar mistake.
Seems like your api is not not accessible and its returning error HTML page by default.
You can try below solution:-
I think you are using httpclient to get data to blazor application.
If you have separate projects in solution for blazor and web api,
currently your startup application may set to run blazor project only.
Change startup projects to multiple (blazor and web api app) and give httpClient url in startup of blazor application, as webApi application url, that may solve your issue.
This error indicates a mismatch of the project targeting framework version and installed runtime on the machine. So make sure that the target framework for your project matches an installed runtime - this could be verified by multiple means; one of them is to check out the Individual Components tab of the Visual Studio Installer and lookup the target version.
E.g., there is the TargetFramework attribute in the proj file:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
Then launch the Visual Studio Installer, click Modify, and visit the Individual Components tab:
Install the missing runtime (.NET 5 Runtime in this case) and you're good to go.
I got the same error. Red herring. use your browser or postman to check your api endpoint is returning the json data and not some HTML. In my case my "api/companytypes" had a typo.
private CompanyType[] companytypesarray;
private List<CompanyType> CompanyTypeList;
private List<CompanyType> CompanyTypeList2;
public async Task<bool> LoadCompanyTypes()
{
//this works
CompanyTypeList = await Http.GetFromJsonAsync<List<CompanyType>>("api/companytype");
//this also works reading the json into an array first
companytypesarray = await Http.GetFromJsonAsync<CompanyType[]>("api/companytype");
CompanyTypeList2 = companytypesarray.ToList();
return true;
}
I know this is an old question, but I had the same problem. It took some searching, but I realized that the return data was in XML instead of JSON.
I'm assuming your "http" variable is of type HttpClient, so here's what I found worked for me.
By setting the "Accept" header to allow only JSON, you avoid a miscommunication between your app and the remote server.
http.DefaultRequestHeaders.Add("Accept", "application/json");
States = await http.GetJsonAsync<List<string>>("api/account/getstatesforprofile");
I had the same issue when passing in an empty string to a controller method. Creating a second controller method that doesn't accept any input variables, and just passing an empty string to the first method helped to fix my problem.
[HttpGet]
[ActionName("GetStuff")]
public async Task<IEnumerable<MyModel>> GetStuff()
{
return await GetStuff("");
}
[HttpGet("{search}")]
[ActionName("GetStuff")]
public async Task<IEnumerable<MyModel>> GetStuff(string search)
{
...
}
Versions of package
Try to update your packages to old or new version. In my case, system.net.http.json is updated from 6.0 to 5.0
Likely you are using an Asp.NetCore hosted WASM application. By default the client's App.razor has something similar to:
<CascadingAuthenticationState>
<Router AppAssembly="#typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView DefaultLayout="#typeof(MainLayout)"
RouteData="#routeData">
<NotAuthorized>
<RedirectToLogin />
</NotAuthorized>
<Authorizing>
<Loading Caption="Authorizing..."></Loading>
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="#typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
Herein lies the problem. Since the Client and Server share the same base address, when the application cannot find "api/account/getstatesforprofile" it gives you the client's "Sorry, there's nothing at the address" page. Which is of course HTML.
I have not found the solution to this issue, but I am working on it and will reply once I find an issue.
I was having the same problem,
"JsonReaderException: '<' is an invalid start of a value."
In my case the url for the REST service was wrong.
I was using the URL from the client project. Then I looked at the Swagger screen,
https://localhost:44322/swagger/index.html
and noticed the right URL should start with "44322"...
Corrected, worked.
In my case, I had a comma (,) written mistakenly at the beginning of the appsettings.json file ...
Just check your file and verify
///////
my error details
//////
System.FormatException HResult=0x80131537 Message=Could not parse the JSON file.
Source=Microsoft.Extensions.Configuration.Json StackTrace: at line 16 This exception was originally thrown at this call stack: [External Code] Inner Exception 1: JsonReaderException: ',' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
////
For me, most of the time it is the #lauri-peltonen answer above. However, now and again, depending on who wrote the controller I have found that this will work in Swagger but not when you call it via the client (at least in this Blazor project we are on.)
[HttpGet]
[Route("prog-map-formulations")]
public async Task<List<GetProgramMapFormulationsResult>> GetProgramMapFormulations(int formulationId)
{
...
}
It sends the request as:
api/formulation-performance-program-map/analytical-assoc-values?formulationId=1
And I get results in Swagger but failes with the '<' OP error.
When I change ONLY the route to:
[HttpGet]
[Route("prog-map-formulations/{formulationId:int}")]
public async Task<List<GetProgramMapFormulationsResult>> GetProgramMapFormulations(int formulationId)
{
...
}
It sends the request as:
api/formulation-performance-program-map/analytical-assoc-values/1
And this works in both Swagger as well as from the Client side in Blazor.
Of course, once updated, I did have to clear the cache!
If you delete "obj" folder in your directory then clean the solution and rebbuild it the exception will be resolved
In all these, there is two things that was my issue and realized, first off was that Route[("api/controller")] instead of Route[("api/[controller]")], that is missing square brackets. In the second exercise I was doing, with the first experience in mind, was from the name of the database. The database had a dot in the name (Stock.Inventory). When I change the database name to StockInventory it worked. The second one I am not so sure but it worked for me.

In Laravel Dusk Stripe Testing how do i fix "In W3C compliance mode frame must be either instance of WebDriverElement, integer or null"

My application was laravel framework 5.8 and i am currently upgrading it to 6.0.
My Laravel Dusk browser tests include logging into Stripe, creating a user and a subscription before testing the application functionality.
I am using Google Chrome Version 80.0.3987.132 (Official Build) (64-bit)
I have set the Dusk chrome driver to the same using the usual command...
php artisan dusk:chrome-driver 80
My phpunit tests are now all running fine. My dusk tests start to run but when they get to the stripe login stage they return the error
InvalidArgumentException: In W3C compliance mode frame must be either instance of WebDriverElement, integer or null
The section of the Dusk test it is throwing this error at is:
$this->browse(function (Browser $browser) use ($recr1, $screenshotEnabled) {
$browser->waitFor('iframe[name=__privateStripeFrame5]');
$browser->driver->switchTo()->frame('__privateStripeFrame5');
I realise it probably isn't best practise to ignore/paper over the issue but to keep the upgrade to laravel 6.0 moving i have tried setting w3c compliance to false following the suggestions in:
How to turn off w3c in chromedriver to address the error unknown command: Cannot call non W3C standard command while in W3C
and
https://github.com/laravel/dusk/issues/624
by modifying DuskTestCase.php but to no avail.
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--no-sandbox',
'--window-size=1920,1080',
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()
->setCapability(ChromeOptions::CAPABILITY, $options)
->setCapability('alwaysMatch', ['goog:chromeOptions' => ['w3c' => false]])
, 60*1000, 60*1000
);
}
}
I think the correct action is actually to address the issue head on and modify the way i reference the stripe frame i.e.
$browser->waitFor('iframe[name=__privateStripeFrame5]');
$browser->driver->switchTo()->frame('__privateStripeFrame5');
but im not sure how to do this.
I think i might need toswitch back to the default frame but have yet to get that working...
https://laracasts.com/discuss/channels/laravel/dusk-click-element-in-iframe?page=1
$this->driver->switchTo()->defaultContent()->switchTo()->defaultContent();
Any thoughts/recommendations greatly appreciated guys.
Seems I have sorted the problem.
The switchTo wasn't working...
$browser->waitFor('iframe[name=__privateStripeFrame5]');
$browser->driver->switchTo()->frame('__privateStripeFrame5');
so instead i used withinFrame...
$browser
->waitFor('iframe[name=__privateStripeFrame5]')
->withinFrame('iframe[name=__privateStripeFrame5]', function($browser){
...
});
Thanks to tgugnani in his post...
https://www.5balloons.info/working-with-iframe-in-laravel-dusk/

After uploading Laravel to server I get an error message on my routes page

I'm almost done with a Laravel project I'm working on and am wanting to try it out on an actual server.
However after I loaded the entire project (slower than using composer but I was hoping to keep this as simple as possible the first time I tried this) I can't even log in as I'm getting a "syntax error, unexpected '['" error message with the debug window pointing to this code:
Route::get('login', [
'as' => 'login',
'uses' => 'SessionsController#create'
]);
I tried changing it to
Route::get('login', array(
'as' => 'login',
'uses' => 'SessionsController#create'
));
but after I changed it and uploaded the file again it still looked like the original code. To make things more confusing the code should work either way, unless I am missing something.
If anyone can point out 1.)the reason for the error message - the project runs fine on my local server and 2.)why the file does not seem to be updating when I send in a new version it would be greatly appreciated! Thanks!
Your actual server is running PHP 5.3
Your local server is running PHP >=5.4
The short array syntax [] was added in PHP 5.4. See change log here.

How to solve the "error 500" issue of Symfony PHP framework with Webkit browsers?

I'm having an issue with the visualization of my site on Google Chrome and Safari (both using Webkit rendering engine), the site is built upon Symfony framework, version 1.1 (unmaintained version).
When navigating to the site, this shows an error 500 when loading a page, I read somewhere that it might be related to Symfony caching but I don't know how to solve it and turning off caching is not a solution.
Thankyou in advance.
This ticket fixes the problem, so you can patch your sfWebRequest class code.
You can see the actual problem by browsing via "dev" controller. It's called by default: yourAppName_dev.php
So if you have a "frontend" app, it's:
http://domain.tld/frontend_dev.php
Yes, most of the cases for error 500 is the cache. You can clear the cache by navigating to your project root directory and type:
symfony cc
or
./symfony cc
or
php symfony cc
which depends of you environment and setup.
Also you can delete the content of the cache directory located in your project root manually.
Hope this helps.
See this: http://forum.symfony-project.org/index.php/m/75225/
To fix, change your config/ProjectConfiguration.class.php to include the following:
public function setup()
{
// keep current code here and then add...
$this->dispatcher->connect('request.filter_parameters', array($this, 'filterRequestParameters'));
}
public function filterRequestParameters(sfEvent $event, $parameters)
{
$request = $event->getSubject();
if (preg_match('|Safari/([0-9\.]+)|', $request->getHttpHeader('User-Agent')))
{
$request->setRequestFormat('html');
}
return $parameters;
}