I started to work with twitter API and I'm using TwitterOAuth library but when I run it I get this error:
Fatal error: Uncaught exception 'Abraham\TwitterOAuth\TwitterOAuthException' with message 'error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol' in C:\wamp\www\tweeterapp\twitteroauth\src\TwitterOAuth.php on line 400
and my code is :
session_start();
require_once("twitteroauth/autoload.php");
use Abraham\TwitterOAuth\TwitterOAuth;
$twitteruser = "blah";
$notweets = 30;
$consumerkey = "blah";
$consumersecret = "blah";
$accesstoken = "blah-blah";
$accesstokensecret = "blah";
$connection = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$content = $connection->get("statuses/home_timeline", array("count" => 25,"exclude_replies" => true));
echo json_encode($content);
Related
I am trying to get response from an api using GuzzleHttp but it is showing error cURL error 7: Failed to connect to ***********.com port 8009 after 569 ms: Connection refused .Below is my controller function . How to solve this issue
use GuzzleHttp\Client;
class DailyAttendanceController extends Controller
{
public function index()
{
$client = new Client();
$res = $client->request('GET', '**************', ['auth' => ['', '']]);
$result = $res->getBody();
$data = json_decode($result,true);
}
}
I have a problem on an API call with the Guzzle 7.4.3 library to PATCH severals produced on Akeneo 5.0.50
By following the documentation below:
https://api.akeneo.com/api-reference.html#patch_products
I first tested the api via Postman here is the result:
Res Postman
However with the guzzle code this one doesn't work and returns a null body with a 200 code.
Here is the code:
public function patchProductGlobalAkeneo(string $token_akeneo, string $data_products): object
{
try {
$request = $this->client->request('PATCH', $_ENV["AKENEO_API_URL"] . $_ENV["AKENEO_API_URL_PRODUCTS"], [
'headers' => [
'Authorization' => 'Bearer ' . $token_akeneo,
'Content-Type' => 'application/vnd.akeneo.collection+json'
],
'json' => json_decode('{"identifier":"01750003001400","values":{"stock":[{"data":"10","locale":null,"scope":null}]}}
{"identifier":"01750003001400","values":{"stock":[{"data":"10","locale":null,"scope":null}]}}')
]);
} catch (RequestException $e) {
$res = new stdClass();
$res->content = json_decode($e->getResponse()->getBody()->getContents());
$res->status_res = $e->getResponse()->getStatusCode();
var_dump($res->status_res);
var_dump("ERROR");
return $res;
}
$res = new stdClass();
$res->content = json_decode($request->getBody()->getContents());
$res->status_res = $request->getStatusCode();
var_dump($res->content);
var_dump($res->status_res);
var_dump("GOOD");
return $res;
}
The result of the var_dump : Res Var_dump
I received an error after updating and uploading a picture in Laravel.
InvalidArgumentException
Screenshot of error
Controller
public function actedit(Request $Request, $id)
{
$user = User::find($id);
$user->title = $Request->input('title');
$user->description = $Request->input('description');
$user->url = $Request->input('url');
$file = $Request->file('avatar');
if (!$file) {
return redirect()->route('editprofile')->with('alert', 'foto harus diisi!');
}
$file_name = $file->getClientOriginalName();
$path = public_path('/img');
$file->move($path, $file_name);
$user->image = 'public/img/'.$file_name;
$user->save();
return redirect('profile/'.$id);
}
Route
Route::post('/edit/{id}', 'HomeController#actedit')->name('actedit');
Code to create a new user:
function New-DropBoxUser {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
[string]$FullName
)
# Split name into username #
$FirstName, $LastName = $FullName.split(' ')
$UserName = ($FirstName[0]+$LastName).toLower()
$email = "$UserName#mycomp.com"
$Body = #{
"new_members" = #(#{
"member_email" = $email;
"member_given_name" = $FirstName;
"member_surname" = $LastName;
"send_welcome_email" = "true";
"role" = #{
".tag" = "member_only"
}
})
}
Write-Host ''
Write-Host 'Creating DropBox User...' -ForegroundColor 'Yellow' -BackgroundColor 'Black'
$AuthToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
$token = "Bearer $AuthToken"
$response = Invoke-RestMethod `
-Method Post `
-Uri "https://api.dropboxapi.com/2/team/members/add" `
-Headers #{ Authorization = $token } `
-ContentType "application/json; charset=utf-8" `
-Body (ConvertTo-Json $Body)
}
Output:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
Anyone, please tell me the fix. I tried the Endpoint "team/members/list" to fetch user list using the same $token and it works.
I am totally new to Dropbox API so my code is borrowed from Google, while being good with PowerShell I tried to patch up using many different codes but none worked.
When all else fails, RTFM, whose parameters say:
{
"new_members": [
{
"member_email": "tom.s#company.com",
"member_given_name": "Tom",
"member_surname": "Silverstone",
"member_external_id": "company_id:342432",
"send_welcome_email": true,
"role": "member_only"
}
],
"force_async": false
}
Try removing .tag from the role definition and replace "true" with $true
$Body = #{
"new_members" = #(#{
"member_email" = $email
"member_given_name" = $FirstName
"member_surname" = $LastName
"send_welcome_email" = $true
"role" = "member_only"
})
}
I want to use PDO with my Slim php application. When I use a simple select query and send json data to Twig page. But I keep getting this error : Slim Application Error
This is my code :
<?php
require __DIR__ . '/vendor/autoload.php';
$app = new Slim\App;
$container = $app->getContainer();
$container['view'] = function ($container) {
$templates = __DIR__ . '/templates/';
$cache = __DIR__ . '/tmp/views/';
$view = new Slim\Views\Twig($templates, array('cache' => false));
return $view;
};
$container['db'] = function ($container) {
$pdo = new PDO("mysql:host=localhost;DBName=dbsat", "root", "");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
};
$app->get('/', function ($request, $response) {
$sth = $this->db->prepare("SELECT * from client where id=:id");
$sth->bindParam("id", 1);
$sth->execute();
$todos = json_encode($sth->fetchAll());
$data = ['user' => $todos];
return $this->view->render($response, 'home.twig', $data);
});
$app->get('/login', function ($request, $response) {
return $this->view->render($response, 'login.twig');
});
$app->run();
?>
The problem appears at this line :
$sth = $this->db->prepare("SELECT * from client where id=:id");
Problem solved. It was caused by binding param
Message: Cannot pass parameter 2 by reference
By knowing the error I have fixed it. Thank you all.