Example #1
0
static drbClient *CreateClient (char *token_key_s, char *token_secret_s)
{
	drbClient *client_p = NULL;
	
	const json_t *dropbox_json_p = GetGlobalConfigValue ("dropbox");

	if (dropbox_json_p)
		{
			const char *key_s = GetJSONString (dropbox_json_p, "key");
			const char *secret_s = GetJSONString (dropbox_json_p, "secret");

			if (key_s && secret_s)
				{
					/* Global initialisation */
					drbInit ();

					client_p = drbCreateClient ((char *) key_s, (char *) secret_s, token_key_s, token_secret_s);

					if (client_p)
						{
							// Request a AccessToken if undefined (NULL)
							if (! (token_key_s && token_secret_s))
								{
									bool success_flag = false;
									drbOAuthToken *req_token_p = drbObtainRequestToken (client_p);

									if (req_token_p)
										{
											drbOAuthToken *acc_token_p = NULL;
											char *url_s = drbBuildAuthorizeUrl (req_token_p);
											printf("Please visit %s\nThen press Enter...\n", url_s);
											free (url_s);
											fgetc (stdin);

											acc_token_p = drbObtainAccessToken (client_p);

											if (acc_token_p)
												{
													// This key and secret can replace the NULL value in t_key and
													// t_secret for the next time.
													printf("key:    %s\nsecret: %s\n", acc_token_p -> key, acc_token_p -> secret);
													success_flag = true;
												}
											else
												{
													fprintf(stderr, "Failed to obtain an AccessToken...\n");
												}
										}
									else
										{
											fprintf(stderr, "Failed to obtain a RequestToken...\n");
										}

									if (success_flag)
										{
											/* Set default arguments to not repeat them on each API call */
											drbSetDefault (client_p, DRBOPT_ROOT, DRBVAL_ROOT_AUTO, DRBOPT_END);
										}
									else
										{
											drbDestroyClient (client_p);
											client_p = NULL;
										}

								}		/* if (! (token_key_s && token_secret_s) */

						}		/* if (client_p) */

				}		/* if (key_s && secret_s) */

		}		/* if (dropbox_json_p) */

	
	return client_p;
}
Example #2
0
gpointer upload_file (gpointer data) {
    
    int err;
    void* output;
    
    // Application key and secret. To get them, create an app here:
    // https://www.dropbox.com/developers/apps
    char *c_key    = "lmg4kv8jw45nlsr";  //< consumer key
    char *c_secret = "xmq9x391l0y8nwy";  //< consumer secret
    char filename[200];
    CustomData *cdata=(CustomData*)data;
    strcpy(filename,cdata->sink_filename);
    
    // User key and secret. Leave them NULL or set them with your AccessToken.
   // char *t_key    = NULL; //< access token key
   // char *t_secret = NULL;  //< access token secret
     char *t_key    = "5j55oq1lf8h1zi2w"; //< access token key
     char *t_secret = "nvv5ps3hy4v4wy3";  //< access token secret
    
    // Global initialisation
    drbInit();
    
    // Create a Dropbox client
    drbClient* cli = drbCreateClient(c_key, c_secret, t_key, t_secret);
    
    // Request a AccessToken if undefined (NULL)
    if(!t_key || !t_secret) {
        drbOAuthToken* reqTok = drbObtainRequestToken(cli);
        
        if (reqTok) {
            char* url = drbBuildAuthorizeUrl(reqTok);
            printf("Please visit %s\nThen press Enter...\n", url);
            free(url);
            fgetc(stdin);
            
            drbOAuthToken* accTok = drbObtainAccessToken(cli);
            
            if (accTok) {
                // This key and secret can replace the NULL value in t_key and
                // t_secret for the next time.
                printf("key:    %s\nsecret: %s\n", accTok->key, accTok->secret);
            } else{
                fprintf(stderr, "Failed to obtain an AccessToken...\n");
                return NULL;
            }
        } else {
            fprintf(stderr, "Failed to obtain a RequestToken...\n");
            return NULL;
        }
    }
    
    // Set default arguments to not repeat them on each API call
    drbSetDefault(cli, DRBOPT_ROOT, DRBVAL_ROOT_AUTO, DRBOPT_END);
    

    // upload current file
   
    FILE *file = fopen(filename, "r");
    char fn[200];
    memset(fn,0,sizeof(fn));
    strcpy(fn,"/");
    strcat(fn,filename);
	output = NULL;	
        err = drbPutFile(cli, &output,
                         DRBOPT_PATH, fn,
                         DRBOPT_IO_DATA, file,
                         DRBOPT_IO_FUNC, fread,
                         DRBOPT_END);
        printf("File upload: %s\n", err ? "Failed" : "Successful");
    
   fclose(file); 
    

   output = NULL; 

    //share public link to file
	drbShare(cli, &output,
					DRBOPT_PATH, fn,
					DRBOPT_END);
	drbLink* url = (drbLink*)output;
//	strcpy(link,url->url);  We should return here!!!!
 
    drbDestroyClient(cli);
    
    // Global Cleanup
    drbCleanup();
    gst_bus_post(cdata->bus,gst_message_new_application(
        GST_OBJECT_CAST(cdata->pipeline),
        gst_structure_new_empty("UploadDone")));
    return url->url;
}