PHP Post not working with twitter api - php

Im trying to use the following PHP to add a favorite to my account:
<?php
if(isset($_POST['submit'])) {
$fav = $_REQUEST['fav'];
$connection->post('favorites/create', array('id' => $fav));
echo "<div style='padding-bottom: 5px; color: #0099FF;'>Fav Created Successfully.</div>";
}
?>
With the following form:
<form id="fav" method='post' action='index.php'>
<input type="text" style="width: 346px;" name="fav" id="fav" ></input>
<input type="submit" value="Fav This!" name="submit" id="submit" />
</form>
Its not creating a favorite, Can anyone spot anything wrong with it?
PS: I am using the OAuth API:
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

$response = $connection->post('favorites/create/'.$fav);
The ID is not a parameter.

Im trying to use the following PHP to add a favorite to my account:
$favorite = $connection->post('favorites/create/'.$id);
where $id is the status id but favorite don't return nothing

If I'm not mistaken, you don't need to add an "id" parameter.
Looking at Twitter's Documentation the URL to create a favorite would be http://api.twitter.com/1/favorites/create/12345.xml where "12345" is the ID of the tweet.

When I tried it, it says the following.
This method requires a GET.
Although Twitter API documentation says it requires a POST. So, try to do a GET request on it:
$response = $connection->get('favorites/create', array('id' => $fav));
// now print the response to see if any error pops up:
print_r($response);

Related

Object Moved error html to php

I honestly don't know what's wrong. Every time I try to add an account to my xml database file, it doesn't get written in the file. I don't see anything wrong with my code.
When I click my submit button this page's content is displayed
Object Moved
This document may be found here
//This is me testing my code below
hey im in the if statement
hogwartsBoss
swag
hogwartsBoss#gmail.com
Harry
Potter
BabyMetal Head Bangya!!
Iron Madien Run to the Hills
japybunnyhijapygen#yahoo.com genesis Bejarano
HTML SIGN UP FILE
<!--This is the sign up section on the Home Website page -->
<form method="post" action="sign_up.php">
First Name:<input type= "text" name="first"/><br /><br />
Last Name:<input type= "text" name="last"/><br /><br />
Email:<input type= "text" name="email"/><br /><br />
Username:<input type= "text" name="username"/><br /><br />
Password:<input type= "password" name="password"/><br /><br />
<input type= "submit" name="submit" value="Sign up"/>
</form>
PHP SIGN UP FILE
$f = $l = $e= $user = $pass = null;
if(isset($_POST['username']) && !empty($_POST['username'])) {
echo "hey im in the if statement";
include 'xmlconnect.php';
$f=vaildName($_POST['first']);
$l=vaildName($_POST['last']);
$e=vaildEmail($_POST['email']);
$user= $_POST['username'];
$pass= $_POST['password'];
$credTag = $xml->addChild('credentials');
//user account info
$userTag = $credTag->addChild('username',$user);
$passTag = $credTag->addChild('password',$pass);
$emailTag = $credTag->addChild('email',$e);
$infoTag = $credTag->addChild('info');
$firstTag = $infoTag->addChild('first',$f);
$lastTag = $infoTag->addChild('last',$l);
file_put_contents('UserAccountDB.xml',$xml->asXML());
echo $xml->asXML();
// echo "updated database";
// printf($xml);
//redirects you to the homepage
session_start();
$_SESSION['userName'] = $user;
//$url = "http://cs3360.cs.utep.edu/gbejarano/WebStore/UserAccountDB.xml";
//$url = "http://cs3360.cs.utep.edu/gbejarano/WebStore/myLibrary.php";
//$url = 'http://localhost/Music_Webstore/myLibrary.php';
header('Location: '.$url);
}
There is a great misunderstanding here:
Object Moved
This document may be found here
is not an error message. It's your web-server's standard response body of a message in the Redirect 3xx group. Those do not denote errors, just standard redirects.
Those redirects are expected because you answer with a redirect:
header('Location: '.$url);
However using
echo $xml->asXML();
before the header command does not work at all. Please consult the PHP manual on how to do a proper redirect and related to other existing Q&A material here on site as well before you draw wild assumptions in a new question and label non-errors as errors and cause other confusion.
If certain words are not clear to you, ask about the words first.
If you have problem to decipher a message the computer gives to you, ask about the message first.
Do not post live code. Instead create a new example from scratch that contains as little code and data as necessary to reproduce your issue.
Sometimes the solution is simple:
It wasn't my code it was my school server security

Zend Framework 2 can´t receive HTTP Post - "get was unable to fetch or create an instance for fromPost"

I´m new in ZF2 and I have a problem with reveiving the post/get Parameters in my Controller.
Following Exception appears:
Zend\ServiceManager\Exception\ServiceNotFoundException
Zend\Mvc\Controller\PluginManager::get was unable to fetch or create an instance for fromPost
My index.phtml
...
<form id="formActionCl" action="/public/checklistCore/delete" method="post">
<input type="submit" id="butto_doAction<?php echo $index;?>" hidden="true" value="<?php echo $this->translate('button_confirm_action', 'checklist');?>"/>
<input type="hidden" id="checklist" value="<?php echo $index;?>">
</form>
...
And the Controller:
use Zend\Mvc\Controller\Plugin\AbstractPluginManager,
...
public function deleteAction()
{
$cl_id = $this->fromPost('checklist');
echo $cl_id;
//$cl_id = $_GET['checklist'];
$checklist = $this->getEntityManager()->getRepository('ChecklistCore\Entity\Checklist')->find($cl_id);
$checklist->status = 'inactiv';
$this->getEntityManager()->persist($checklist);
$this->getEntityManager()->flush();
return $this->redirect()->toUrl('index');
}
I think I have forgott something in the module.config, but I can´t find anything, how to declare the serviceManager right (module.config.php)
Two changes are needed. First, as Tim wrote, it should be
$cl_id = $this->params()->fromPost('checklist');
Second, form items are passed to the controller by name, not id. So in addition to the id field on the element, you need a name field, as follows:
<input type="hidden" id="checklist" name="checklist" value="<?php echo $index;?>">
I think you mean:
$cl_id = $this->params()->fromPost('checklist');
assuming you're trying to grab a POST variable.

IMDB API to php variables

Hello stackoverflow users. I need to pull some movie information from the Open Movie Database API. They have no docs on how to use their API so i am very confused. The site i am creating in PHP needs to pull some variables or strings from their api depending on what imdb ID i put in an form. Here is the code i got so far. This gives me: "http://www.omdbapi.com/?i=tt1092026". But i need to get the strings of their API and make them to variables so i can use them in forms later. How do i do this? Please help. Thanks! :D
<form action="?action=grab" method="post">
<input placeholder="tt1092026" type="text" name="id" id="id">
<input type="submit" class="button" value="Grab Movie">
</form>
<?php if ($_GET[action] == "grab") { ?>
<h9>
<?php
$id = $_POST["id"];
$url = "http://www.omdbapi.com/?i=$id";
echo $url;
?>
</h9>
<?php }; ?>
You need to decode the response and assign it to variables (all in PHP).
<?php
$id = $_POST["id"];
$url = file_get_contents("http://www.omdbapi.com/?i=$id");
$json = json_decode($url, true); //This will convert it to an array
$movie_title = $json['Title'];
$movie_year = $json['Year'];
//and so on...
and then when you need to echo them:
echo $movie_title;
or
echo "The movie '$movie_title' was made in $movie_year.";
I think TMDB is is a better API. http://www.themoviedb.org
They have very good documentation here: http://docs.themoviedb.apiary.io
I'm using this in my own web application and it works like a charm.

Posting to Twitter/Weibo using PHP without API support (post form spoofing?)

I'm trying to make a PHP script that can post to groups on Sina Weibo, a Chinese Twitter clone. Other than group functionality, Weibo seems pretty much identical to Twitter in implementation (even in API) -- hence I'm mentioning Twitter as the analogy, as the distinction's irrelevant for my question.
I can make regular posts by API just fine, but the thing is, Weibo's API does not support posting to groups, presumably due to potential spamming hazards that might entail. (Note: my intention wasn't to spam millions with crap, but to get a script to automatically post info on patent expiries to relevant industry groups each day.)
Now, I know there should be a work-around, as there's an application that allows one to manually post to groups (新浪微群自动群发精灵), though the source is private. So I tried to check the post form data sent to the server using Firebug to see if I could replace the API tweet command by manually making the PHP script replicate the post form info, but to no avail.
Here is my code for the callback.php file, called after establishing the OAuth connection. The working API method to post an update has been commented out in favor of the dysfunctional post form method (in HTML tags).
<?php
session_start();
include_once( 'config.php' );
include_once( 'saetv2.ex.class.php' );
$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );
if (isset($_REQUEST['code'])) {
$keys = array();
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = WB_CALLBACK_URL;
try { $token = $o->getAccessToken( 'code', $keys ) ; } catch (OAuthException $e) {}
}
if ($token) {
$_SESSION['token'] = $token;
setcookie( 'weibojs_'.$o->client_id, http_build_query($token) );
?><html><head></head><body>
<form action="http://www.weibo.com/aj/mblog/add?__rnd=1340066897833" method="post">
<input type="hidden" name="_surl" value="">
<input type="hidden" name="_t" value=0>
<input type="hidden" name="location" value="home">
<input type="hidden" name="module" value="stissue">
<input type="hidden" name="pic_id" value="">
<input type="hidden" name="rank" value="">
<input type="text" name="text" value="测试发表微博 test message" />
<input type="submit">
</form></body></html><?
/*
$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );
$msg = $c->update("测试发表微博 test message");
if ($msg === false || $msg === null){ echo "Error occured"; return false;}
if (isset($msg['error_code']) && isset($msg['error'])){ echo ('Error_code: '.$msg['error_code'].'; Error: '.$msg['error'] ); return false;}
echo($msg['id']." : ".$msg['text']." ".$msg["created_at"]);
*/
} else echo('授权失败。 authentication failed');
?>
I'm pretty new to all of this, so I'm probably missing something obvious, but would anyone here know enough about Twitter/Weibo to locate the problem here? Would there perhaps be an easy workaround?
Thanks!
Been a while, but for anyone stumbling upon this thread: by now I caught up a bit, and it seems like browser automation with Ruby gem Watir would have much better chances of working than form spoofing.

Log into a site using PHP's HttpRequest?

I'm looking for a way to search for business "X" on LinkedIn, which requires a valid login session. I'm making Http requests with PHP's HttpRequest object, but I'm not familiar enough with handling session data/cookies to figure out how to pinpoint my mistake.
$loginURL = "https://www.linkedin.com/uas/login-submit";
$loginPostData = array("session_key" => "mylogin#mydomain.com",
"session_password" => "itsasecret",
"source_app" => "",
"signin" => "",
"session_redirect" => "",
"csrfToken" => "",
"sourceAlias" => "",
);
$httpRequest = new HttpRequest($loginURL, HttpRequest::METH_POST);
$httpRequest->setContentType("application/x-www-form-urlencoded");
$httpRequest->addPostFields($loginPostData);
$httpRequest->setOptions(array("redirect" => 10));
$httpMessage = $httpRequest->send();
$responseBody = $httpMessage->getBody());
I write $responseBody to a file and open it in a browser, but it only contains a generic LinkedIn page with log in fields. Using the "Tamper Data" extension to firefix, I can see that the following request headers allow firefox to load a session-viewable webpage:
Host=www.linkedin.com
Content-Type=application/x-www-form-urlencoded
Content-Length=124
POSTDATA=source_app=&session_key=mylogin#mydomain.com&session_password=itsasecret&signin=&session_redirect=&csrfToken=&sourceAlias=
There's something weird about the data I get back too: I'd expect to see something like "invalid username or password", but I get the default linkedin.com page.
Actually looking at the code of linkedin there are some hidden input that you need to send as POST datas, because your request has not one or more of these values you got the same login page...
Copy & paste from linkedin
<input type="hidden" name="source_app" value="">
<input type="hidden" name="trk" value="guest_home_login">
<input type="hidden" name="session_redirect" value="" id="session_redirect-login"><input type="hidden" name="csrfToken" value="ajax:9034582961576232024" id="csrfToken-login"><input type="hidden" name="sourceAlias" value="0_7r5yezRXCiA_H0CRD8sf6DhOjTKUNps5xGTqeX8EEoi" id="sourceAlias-login">

Categories