0

Can someone help me set the Facebook API to post on wall text, image and link using asp classic?

The random script is easy but I can't seem to set the API. Read several doc in Facebook developer but its all for PHP.

This is my script, how can I post the image and text to Facebook?

dim myFileSys, Folder, FileName, urlpath, num, rsfb, conn, textfb, intGEN


Set myFileSys = Server.CreateObject("Scripting.FileSystemObject")
Set Folder = myFileSys.GetFolder(Server.MapPath("/ftpupload/imagens"))  

sub gen_pass(max_num)
     dim gen_array(62)

     gen_array(0) = "0"
     gen_array(1) = "1"
     gen_array(2) = "2"
     gen_array(3) = "3"
     gen_array(4) = "4"
     gen_array(5) = "5"
     gen_array(6) = "6"
     gen_array(7) = "7"
     gen_array(8) = "8"
     gen_array(9) = "9"

     Randomize

     do while len(output) < max_num
        num = gen_array(Int((9 - 0 + 1) * Rnd + 0))
        output = output + num
     loop

     gen_pass = output
     intGEN = CInt("2")
End sub

sub radm
    call gen_pass(max_num)
    For each file in Folder.Files
         if num="" then
            num="0"
         else
            num=num+1
         end if
         if num=intGEN then
             FileName = file.name
         end if    
    next
end sub    

do while filename="" 
    call radm
loop    

urlpath = "/ftpupload/imagens/"&filename    
response.write urlpath

set conn = Server.CreateObject("ADODB.Connection")  
conn.ConnectionString = "Driver={MYSQL ODBC 5.1 DRIVER};Server=localhost;Port=3306;Database=fbposter;Uid=root;Pwd=1234;" 
conn.Open() 

Set rsfb = conn.Execute("Select * From facetext ORDER BY RAND() LIMIT 0,1")

if rsfb.eof then
    textfb=rsfb.text
end if


Set myFileSys = nothing
set folder = nothing
set FileName = nothing
set urlpath = nothing
set num = nothing
set rsfb = nothing
set textfb = nothing
set intGEN = nothing
conn.close
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
razstec
  • 93
  • 2
  • 11
  • 1
    what have you tried? Give us a sample of you code with the API urls... I know nothing about asp, but someone surely does. Even if nobody else knows about the correct API urls (unlikely), I surely do – tattvamasi Sep 02 '13 at 14:24
  • i haven't tried nothing because i never work with api´s, i dont know how to merge the random script with the facebook posting code. – razstec Sep 02 '13 at 15:00
  • well the api url to post a status update for the user is https://graph.facebook.com/USERID/feed with POST http request and the authorization token, so you have to basically make at least two calls (one to get the auth token, one to post) – tattvamasi Sep 02 '13 at 17:54
  • i can do that with the graph api explore but how can i put that in the page code? – razstec Sep 03 '13 at 17:20
  • I'm terribly sorry but I know nothing about ASP and ASP.NET...There must be a way to make an HTTP request, but I have no idea. The closest thing I have is C# – tattvamasi Sep 03 '13 at 23:15
  • can you give me an example with php? maybe i can change it to asp – razstec Sep 04 '13 at 14:00
  • edited the answer. That works for me so I tested it. – tattvamasi Sep 04 '13 at 17:46

1 Answers1

0

well the api url to post a status update on behalf of the user is https://graph.facebook.com/USERID/feed with POST http request and the authorization token, so you have to basically make at least three calls (one to get, with GET method, the auth token, one to get the user's info, and one to post, with POST method). The POST "action" has a series of attributes, such as the link, the message, privacy, caption, etc. etc. but don't forget the token or it doesn't work... If you test it with yourself it's going to be easier (because you can get the tokens, and yours never expires, on the Graph Explorer Tool). See if it works.

EDIT: here's an example in php, by Facebook, edited for your purpose.

<?
require '../src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId' => ' ',
  'secret' => ' ',
));

// Get User ID
$user = $facebook->getUser();

// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.

if ($user) { //if there's an user logged in

//build an array with some paramenters
$parameters = array(
    'message' => "isn't it nice when things just work?",
    'picture' => "",
    'link' => "",
    'name' => "",
    'caption' => "",
    'description' => "" //etc. If parameters are blank but at least one is there, it doesn't matter. 
);

//add the access token to it or it doesn't work
$parameters['user_access_token'] = $_SESSION['user_access_token']; //you get this somwhere else before posting

//build a url to call the Graph API with POST HTTP request               
 try {

                $updateyourstatus = $facebook->api("/$user/feed", 'post', $parameters));
            } catch (FacebookApiException $e) {
                d($e);
            }

        }

//Hopefully all brackets are closed.

?>
tattvamasi
  • 845
  • 1
  • 7
  • 14
  • yup! on github, not in asp though - in C# and it only uses `HTTP GET` - [here](https://github.com/Sarasvati/Facebook-Reader). Otherwise there's the Facebook sdk library in PHP [here](https://github.com/facebook/facebook-php-sdk) . It looks like you're posting an update after an upload to me, but I know nothing about asp and that's all I can tell. – tattvamasi Sep 02 '13 at 22:36
  • cant seem to do it :( – razstec Sep 09 '13 at 12:57
  • heaven...:( Is this ASP.NET or asp asp? Can you [do this](https://github.com/Sarasvati/Facebook-Reader/blob/master/FBReader.cs)? Or [this in PHP](http://niclarossini.com/tutorials/)? – tattvamasi Sep 10 '13 at 22:04
  • then I have no chance to be helpful...I've found [this](http://stackoverflow.com/questions/1463635/http-request-post) but I have no idea of the reason why it's XML. – tattvamasi Sep 26 '13 at 16:54