I get a strange error and couldn't find the answer..
This code works well:
$receiverScrName='name';
$method = 'direct_messages/new';
$parameters = array('screen_name' => $receiverScrName, 'text' => 'how are you');
$dm = $oauth->post($method, $parameters);
This code below doesn't work. Only change is "$message" parameter.
$receiverScrName='name';
$message='Hello man';
$method = 'direct_messages/new';
$parameters = array('screen_name' => $receiverScrName, 'text' => $message);
$dm = $oauth->post($method, $parameters);
It gives error:
stdClass Object ( [error] => Could not authenticate with OAuth.
[request] => /1/direct_messages/new.json )
I tried to encode "message" :
$message='Hello man';
$message=urlencode($message);
$method = 'direct_messages/new';
$parameters = array('screen_name' => $receiverScrName, 'text' => $message );
$dm = $oauth->post($method, $parameters);
The message is sent.
But the received message became "Hello+man".
How can i remove "plus" or other escaped characters from the message that will be sended?
Thank you
I found out that this problem is related with non-ASCII characters in message text.
When i transliterate them it is worked.
Related
i'm try to write dailymotion api upload php code
i'm use example code from https://developer.dailymotion.com/guides
it's work great
and i want add Geoblocking only allow Japan
this is my code
require_once 'Dailymotion.php';
// Account settings
$apiKey = 'xxxxxxxxxxxxxxxxxx';
$apiSecret = 'xxxxxxxxxxxxxxxxxx';
$testUser = 'xxxxxxxxxxxxxxxxxx#xxxx.com';
$testPassword = 'xxxxxxxxxxxxxxxxxx';
$videoTestFile = 'C:/output.mp4';
// Scopes you need to run your tests
$scopes = array(
'userinfo',
'feed',
'manage_videos',
);
// Dailymotion object instanciation
$api = new Dailymotion();
$api->setGrantType(
Dailymotion::GRANT_TYPE_PASSWORD,
$apiKey,
$apiSecret,
$scopes,
array(
'username' => $testUser,
'password' => $testPassword,
)
);
$url = $api->uploadFile($videoTestFile);
$result = $api->post(
'/videos',
array(
'url' => $url,
'title' => 'Dailymotion PHP SDK upload test 2',
'tags' => 'dailymotion,api,sdk,test',
'channel' => 'videogames',
'published' => true,
'geoblocking' => 'JP', // i'm add this line
)
);
var_dump($result);
but i got this error
Fatal error: Uncaught exception 'DailymotionAuthRequiredException' with message 'Insufficient rights for the `geoblocking' parameter of route `POST /videos'. Required scopes: manage_videos'
anyone can tell me
what i'm doing wrong and help me fix this problem
thank you
'geoblocking' => 'JP'
change to 'geoblocking' => 'jp'
your code will be
require_once 'Dailymotion.php';
// Account settings
$apiKey = 'xxxxxxxxxxxxxxxxxx';
$apiSecret = 'xxxxxxxxxxxxxxxxxx';
$testUser = 'xxxxxxxxxxxxxxxxxx#xxxx.com';
$testPassword = 'xxxxxxxxxxxxxxxxxx';
$videoTestFile = 'C:/output.mp4';
// Scopes you need to run your tests
$scopes = array(
'userinfo',
'feed',
'manage_videos',
);
// Dailymotion object instanciation
$api = new Dailymotion();
$api->setGrantType(
Dailymotion::GRANT_TYPE_PASSWORD,
$apiKey,
$apiSecret,
$scopes,
array(
'username' => $testUser,
'password' => $testPassword,
)
);
$url = $api->uploadFile($videoTestFile);
$result = $api->post(
'/videos',
array(
'url' => $url,
'title' => 'Dailymotion PHP SDK upload test 2',
'tags' => 'dailymotion,api,sdk,test',
'channel' => 'videogames',
'published' => true,
'geoblocking' => 'jp' // NO , in last line
)
);
var_dump($result);
I am trying to get a request token from Bitbucket but I'm getting "BAD REQUEST - Could not verify OAuth request". I am doing this with drupal and here is the code I have so far:
$key = "MY_KEY";
$secret ="MY_SECRET";
$timestamp = time();
$nonce = (int) (rand() * 100000000);
$callback = 'http://www.google.com'; //'htt//url('<front>', array('absolute' => TRUE)); //DRUPAL_ROOT . "/toolkittens/git";
$url = "https://bitbucket.org/api/1.0/oauth/request_token";
$data = array(
'oauth_nonce' => $nonce,
'oauth_timestamp' => $timestamp,
'oauth_consumer_key' => $key,
'oauth_signature_method' => 'PLAINTEXT',
'oauth_signature' => 'thisismysig',
'oauth_callback' => $callback,
'oauth_version' => '1.0',
);
$options = array(
'method' => 'POST',
'data' => drupal_http_build_query($data),
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
return drupal_http_request($url, $options);
You are providing a PLAINTEXT signature.
If you are requesting a token with the provided signature not encrypted, change your oauth_signature_method to 'PLAINTEXT', so bitbucket knows you didn't encrypt it.
$key = "MY_KEY";
$signature = "MY_SIGNATURE"; //I think this is your secret from bitbucket
$timestamp = time();
$nonce = rand();
$callback = DRUPAL_ROOT . "/toolkittens/git";
$url = "https://bitbucket.org/api/1.0/oauth/request_token";
$data = array(
'oauth_nonce' => $nonce,
'oauth_timestamp' => $timestamp,
'oauth_consumer_key' => $key,
'oauth_signature_method' => 'PLAINTEXT',
'oauth_signature' => $signature,
'oauth_callback' => $callback,
'oauth_version' => '1.0',
);
$options = array(
'method' => 'POST',
'data' => $data,
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$full_url = url($url, array('query' => $data));
return drupal_http_request($full_url);
Also, you defined your options but never used them.
Trying to send pushed at the users local time, not to disturb them.
Need to send push notification at users local time.
The Notification are sent not often with status of their gameplay, I am very aware not to spam users.
Class Helper {
function pwCall( $action, $data = array() ) {
$url = 'https://cp.pushwoosh.com/json/1.3/' . $action;
$json = json_encode( array( 'request' => $data ) );
$res = helper::doPostRequest( $url, $json, 'Content-Type: application/json' );
#json_decode( $res, true );
}
helper::pwCall( 'createMessage', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'notifications' => array(
array(
'send_date' => 'now',
'content' => array('en' => "..your turn to play.",
'fr' => "..votre tour de jouer",
),
'ios_badges' => $row->count,
'devices' => array($pushToken),
'data' => array( 'custom' => 'json data' )
)
)
)
);
Need to replace 'now' with 12:30pm or 13:30 ( military time )
You should put (example):
send_date => "2014-04-01 12:30",
ignore_user_timezone => false
Make sure you schedule notification at least 24 hours in advance if you use Timezeones.
Actually, in order to send a notification according to your users' time zones, all you need is to add the following line in your request:
'ignore_user_timezone' => false,
Then, you can specify the preferred time in 'send_date' section with the format "YYYY-MM-DD HH:mm". Military time would work just fine.
trying to understand zf2.
my code:
$sql = new Sql($dbAdapter);
$insert = $sql->insert('security');
$insert->values(array(
'user' => $userName,
'ip' => '',
'result' => 2
));
$dbAdapter->query($insert->getSqlString(), $dbAdapter::QUERY_MODE_EXECUTE);
error:
Notice: Attempting to quote a value without specific driver level
support can introduce security vulnerabilities in a production
environment. in
/opt/projects/my/newSymbio/current/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Platform/Sql92.php
on line 80
any ideas?
Here is the right syntax of insert in zf2:
$data = array(
''user' => $userName,
'ip' => '',
'result' => '2'
);
$this->tableGateway->insert($data);
and you need to get the object of table in which table to want to insert the data.
Or another way as you are using is:
use Zend\Db\Sql\Sql;
Check you are using above line. And replace your last line with following code:
$selectString = $sql->getSqlStringForSqlObject($insert);
$results = $this->dbAdapter->query($selectString, $dbAdapter::QUERY_MODE_EXECUTE);
And I think you need to call change the $dbAdapter to $this->dbAdapter also try this.
i figure it out.
$sql = new Sql($dbAdapter);
$insert = $sql->insert('security');
$insert->values(array(
'user' => $userName,
'ip' => '',
'result' => 2
));
$statement = $sql->prepareStatementForSqlObject($insert);
$results = $statement->execute();
I used the following code to try to grab tweets from my home_timeline
$tmhOAuth = new tmhOAuth(array('consumer_key' => TW_KEY,
'consumer_secret' => TW_SECRET,
'user_token' => TW_UTOKEN,
'user_secret' => TW_USECRET,
));
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/home_timeline', 'json'));
The $tmhOAuth came from this library here: https://github.com/themattharris/tmhOAuth
For some reason, only one tweet is showing, and it's my most recent one. All my old tweets are not visible. When I change the secrets and keys to that of another user-app, i have similar problme, some tweets are visible while others are not. Does anyone know why it doesnt' just grab all X number of the most recent tweets? Why are some tweets missing?
I download Jimbo's API from github and then did hte following code
<?php
ini_set('display_errors', 1);
require_once('twjimbo/TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "",
'oauth_access_token_secret' => "",
'consumer_key' => '',
'consumer_secret' => ""
);
]
$url = 'https://api.twitter.com/1.1/statuses/home_timeline.json';
$getfield = '?screen_name=anythingworkshere';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$json = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
echo '<pre>'; print_r(json_decode($json)); echo '</pre>';